FastAPI Architecture — The Starlette + Pydantic + Uvicorn Stack
The reality behind FastAPI's "fast" claim
When asked why FastAPI is fast, most say "async support." True, but that's only half.
3-Layer Structure
Uvicorn — ASGI server. uvloop (libuv-based) + httptools (C parser) for HTTP parsing. 2-3x faster than pure Python. This is a big part of "fast."
Starlette — ASGI framework. Routing, middleware, WebSocket, static files. FastAPI inherits Starlette. FastAPI() is a Starlette subclass.
Pydantic — Data validation. V2 core written in Rust (pydantic-core). JSON parsing + validation runs at C/Rust speed.
FastAPI's own code is glue connecting these three layers via type hints. @app.get registers Starlette routes while reading function signature type hints to auto-generate Pydantic validation.
Dev Speed Is Also Part of "Fast"
Just write type hints and you auto-get: request parsing, validation, OpenAPI docs, JSON serialization. Manual implementation would be 3-5x more code.
Key Points
Uvicorn (ASGI server) parses HTTP at C level
Starlette handles routing/middleware
FastAPI reads type hints to auto-generate Pydantic validation
Response also auto-serialized: Pydantic model → JSON