The first FastAPI app I shipped to production took about two hours to write and three weeks to harden. That ratio is honest-the framework gets you to a working endpoint fast, then leaves you to figure out the database sessions, the auth middleware, the test fixtures, and the worker count that won't fall over at 3pm on a Tuesday. This is the guide I wish someone had handed me before I learned all of that the expensive way.
FastAPI's appeal isn't really the speed. Yes, Starlette + Pydantic v2 is fast, and yes, the async story beats Flask into the ground. But what actually makes FastAPI stick is that the same code you prototype on localhost is the code you ship to prod. You don't rewrite. You add a process manager, a reverse proxy, some middleware, and you're done. The hard parts are the parts nobody writes tutorials about: dependency lifecycles, async DB session leaks, background tasks that silently die, and test setups that actually reflect production.
$32
Prerequisites
- Python 3.11 or 3.12. 3.10 works but you're missing
ExceptionGroupniceties and some typing improvements. - A working understanding of
async/await. If you've never writtenasync defbefore, FastAPI will quietly let you write sync handlers and you'll lose half the benefit. - Postgres (or MySQL) locally. We'll use Postgres. SQLite works for prototyping but async SQLite support has rough edges.
- Docker for running Postgres if you don't have it:
docker run -d --name pg -p 5432:5432 -e POSTGRES_PASSWORD=dev -e POSTGRES_DB=app postgres:16. -
httpieorcurlfor hitting the API. The Swagger UI at/docsis fine for poking around, but for scripted testing you want a CLI.
$33
$34
$35
$36
$37
$38
$39
$3a
$3b
$3c
$3d
$3e
$3f
$40
Real-World Use Cases I've Shipped
- SaaS billing API. FastAPI + async SQLAlchemy, handling ~500 RPS at peak. Moved from Flask, saw p99 drop from 400ms to 80ms. The async DB calls were the win-Flask was blocking on every query.
- Internal ML inference gateway. FastAPI in front of a vLLM model server. The FastAPI layer handles auth, rate limiting, and request shaping. The model server stays simple.
-
Webhook receiver. Stripe webhooks, processed via
BackgroundTasksfor fast 200 responses and a real Celery queue for the actual work. Stripe's retry behavior is much friendlier when you respond in <500ms. - Multi-tenant admin panel backend. Tenant resolution as a dependency, all queries automatically scoped. The dependency injection pattern made this trivial; in Flask it would have been request context globals.
Cost Considerations
FastAPI is open source-no licensing. Your costs are infra:
- Single small instance (1 vCPU, 1GB RAM): ~$10-20/month on Fly.io, Render, or Hetzner. Handles ~50-100 RPS for typical CRUD.
- Mid-tier (2 vCPU, 4GB RAM): ~$40-80/month. Handles ~500 RPS with proper tuning.
- Postgres managed (e.g., RDS smallest): ~$15-25/month. Don't run Postgres on the same box as the app in prod.
Developer time is the real cost. A clean FastAPI service takes a senior dev 2-3 days to stand up properly. A messy one takes a week to clean up later. Pay the upfront cost.
Alternatives
- Litestar (formerly Starlite): a FastAPI-compatible framework with a cleaner DI system and better separation of concerns. Worth watching; I'd consider it for new projects in 2025.
- Django Ninja: Django + FastAPI-style API. Great if you need Django's ORM, auth, admin.
- Flask + Smorest: for teams that already know Flask and want OpenAPI generation.
- Express.js (Node) / Actix (Rust) / Fiber (Go): different languages, different tradeoffs. FastAPI wins on developer experience and ecosystem; loses on raw throughput to Go and Rust.
Wrapping Up
FastAPI is the framework I reach for first when building a new API. Not because it's perfect-it has rough edges in the docs, occasional breaking changes between minor versions, and the async-by-default model means you actually need to understand async Python. But the contract between Pydantic models, OpenAPI docs, and the runtime is a real productivity multiplier at scale.
If you take one thing from this: use the dependency injection system properly. Every cross-cutting concern-DB sessions, auth, logging context, rate limits-belongs in a dependency. Once you internalize that pattern, FastAPI stops feeling like a framework and starts feeling like a really well-organized function call graph. That's what makes it scale, in both code and team size.
Originally published on Mango Developer.
Top comments (0)