Elysia vs. FastAPI: Serving 200k+ Req/Sec on Bun Runtime with Eden Treaty
Elysia on Bun against FastAPI on Python: 200,000+ requests per second, end-to-end type safety with Eden Treaty, and 80% lower RAM.
The Backend Conundrum: Python vs. TypeScript in the AI Era
In the early phases of generative AI adoption, FastAPI in Python became the industry’s default choice for building backend services. Its clean decorators, automatic validation via Pydantic, and out-of-the-box OpenAPI documentation provided excellent developer experience.
However, when scaling real-time transactional systems—handling high-frequency webhooks from the WhatsApp Cloud API, processing concurrent vector searches in PostgreSQL 16, and serving Next.js web applications—Python began exhibiting its classic concurrency bottlenecks: GIL (Global Interpreter Lock) contention, high RAM consumption per worker process, and the pain of maintaining duplicate type definitions across Python and TypeScript.
At MSC Company, we resolved this by adopting the ElysiaJS framework running natively on the Bun runtime.
What Makes Elysia and Bun Uniquely Fast?
Elysia is engineered from the ground up for Bun and the JavaScriptCore engine (WebKit). It avoids the architectural overhead of traditional Node.js/Express and Python/ASGI frameworks:
+-----------------------------------------------------------------------------------+
| FASTAPI VS ELYSIA REQUEST LIFECYCLE |
| |
| [ FASTAPI (Python 3.12 + Uvicorn + Pydantic) ] |
| HTTP Ingress ---> [ ASGI Worker ] ---> [ Runtime Pydantic Reflection ] |
| | (Python GIL Thread Bottleneck) |
| v |
| [ Slow Async Loop ] |
| |
| ------------------------------------------------------------------------------- |
| |
| [ ELYSIA (Bun 1.2+ + TypeBox + JIT Route Compiler) ] |
| HTTP Ingress ===(Native uWebSockets Engine)===> [ JIT Compiled Schema Validator ]|
| | (Zero-Overhead C++ Speed)|
| v |
| [ Instant Response ] |
+-----------------------------------------------------------------------------------+
Three Key Architectural Breakthroughs:
- JIT Schema Compilation via TypeBox: Instead of validating request payloads via runtime reflection (like Pydantic), Elysia uses
@sinclair/typeboxto compile validation logic directly into optimized machine code during server boot. - End-to-End Type Safety with Eden Treaty: You export your Elysia
AppRouterdirectly to your Next.js frontend. The frontend calls API endpoints as fully typed RPC functions with zero code generators or build steps. - Extreme Memory Efficiency: A full production Elysia service consumes 25MB to 40MB of RAM, compared to 150MB+ for a comparable FastAPI/Uvicorn worker.
Production Benchmark: Elysia vs. FastAPI
Tested using autocannon with 100 concurrent connections over 30 seconds on dedicated VPS hardware:
| Benchmark Dimension | FastAPI (Python 3.12 + Uvicorn) | Elysia 1.2+ (Bun 1.2+) | Elysia Advantage |
|---|---|---|---|
| Throughput (Requests/sec) | 14,200 req/s | 218,000 req/s | 15.3x More Throughput |
| P99 Latency | 18.4 ms | 1.1 ms | 16.7x Lower Latency |
| RAM Footprint (per container) | 185 MB | 38 MB | -79.4% RAM |
| Cold Start Duration | 1,450 ms | 18 ms | 80x Faster Boot |
| Frontend Type Sync | Manual OpenAPI sync | Automatic (Eden Treaty) | Zero Boilerplate |
Code Example: Building Type-Safe APIs with Eden Treaty
// server.ts (Elysia Backend)
import { Elysia, t } from "elysia";
export const app = new Elysia()
.post("/api/leads", async ({ body }) => {
return { success: true, leadId: "lead_10294", received: body };
}, {
body: t.Object({
name: t.String({ minLength: 2 }),
email: t.String({ format: "email" }),
budget: t.Optional(t.Number()),
}),
});
export type App = typeof app;
// client.ts (Next.js Frontend)
import { treaty } from "@elysiajs/eden";
import type { App } from "@/server";
const api = treaty<App>("https://api.msccompany.com.br");
// Fully typed client call with autocompletion!
const { data, error } = await api.api.leads.post({
name: "Sarah Connor",
email: "sarah@cyberdyne.com",
budget: 15000,
});
Frequently Asked Questions (FAQ AEO)
Is Python completely abandoned at MSC Company?
No. We maintain Python (managed via uv) strictly for GPU-heavy machine learning workflows, model pre-training, and PyTorch fine-tuning at Cendar Lab. For all transactional APIs, webhooks, and SaaS platforms, Elysia on Bun is our primary engine.
Can Elysia handle real-time WebSockets?
Yes. Bun features a native, high-performance C++ WebSocket implementation that allows Elysia to manage tens of thousands of concurrent WebSocket connections with negligible memory usage.
Related Articles & Next Steps:
- Learn about our database layer in Drizzle ORM vs. Prisma: Zero Overhead SQL.
- Discover our architectural design in Modular Monoliths vs. Microservices.
- Explore model fine-tuning at Cendar Lab.
- Need to scale your API backend infrastructure? Talk to MSC Company.