Software Engineering & Data15 de outubro de 2025· Leitura: 3 min

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.

Elysia vs. FastAPI: Serving 200k+ Req/Sec on Bun Runtime with Eden Treaty

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:

  1. JIT Schema Compilation via TypeBox: Instead of validating request payloads via runtime reflection (like Pydantic), Elysia uses @sinclair/typebox to compile validation logic directly into optimized machine code during server boot.
  2. End-to-End Type Safety with Eden Treaty: You export your Elysia AppRouter directly to your Next.js frontend. The frontend calls API endpoints as fully typed RPC functions with zero code generators or build steps.
  3. 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 DimensionFastAPI (Python 3.12 + Uvicorn)Elysia 1.2+ (Bun 1.2+)Elysia Advantage
Throughput (Requests/sec)14,200 req/s218,000 req/s15.3x More Throughput
P99 Latency18.4 ms1.1 ms16.7x Lower Latency
RAM Footprint (per container)185 MB38 MB-79.4% RAM
Cold Start Duration1,450 ms18 ms80x Faster Boot
Frontend Type SyncManual OpenAPI syncAutomatic (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:

Engineering Radar & Technical Inquiries

Scale your operations with audited AI and backend architecture

Subscribe to our technical briefing or submit your system requirements directly to MSC Company's lead architects. Responses within 1 business day.

Applied Engineering & AI

Scale Your Operations with Custom AI Systems

From autonomous WhatsApp agents to sovereign data architecture and fine-tuned SLMs. Talk directly to the MSC Company engineering team.

Contact MSC →
Related Articles

Continue Reading

View all articles →