r/Python • u/Ill_Campaign294 It works on my machine • Aug 03 '26
Discussion Anyone running FastAPI in production with high traffic? How has your experience been?
Quick question, are any of you running fastAPI in production with a high volume of users or heavy traffic? How has your experience with FastAPI been, and how do you handle it?
80
Upvotes
58
u/Ordinary-Sandwich-25 Aug 03 '26
Mine is handling anything under 10000 req/s per worker no problem but getting to that point took a lot of work. Hardest part is making sure your async code is all set up properly such that io is never blocking.
87
u/MathMXC Aug 03 '26
It's been great but make sure you truly understand how async python functions or how anyio handles thread pools (depending on if you use async def or just def for your endpoints).
This article is great: https://fastapi.tiangolo.com/async/#parallel-burgers
25
u/ergo14 Pyramid+PostgreSQL+SqlAlchemy Aug 03 '26
Define "high traffic"? for sites with 200 req/s it's been working without issues for me.
8
u/ManyInterests Python Discord Staff Aug 04 '26
I've used decidedly-slower frameworks (Django) in prod at high levels of traffic with ASGI servers. It works fine. Python in general just gets trickier with giant monoliths (import times, slow startups, etc.), but that's not a traffic/ASGI problem. As long as you're not putting 10M LOC into your service, you should be fine at almost any scale with a commensurate cloud budget.
There are plenty of examples of Python frameworks powering multi-million daily active user sites. FastAPI won't be your problem. Plan to scale horizontally.
7
u/Interesting-Frame190 Aug 04 '26
Its good enough to work and will scale with enough processes/cores. Accedently blocking the event loop (looking at you boto3) can be an issue.
Its no Spring boot at scale and the best python option in my experience. Its a good start, but if things get really high throughput, I'd advise actix web with tokio (Rust) or Gin with go routines (Go).
18
u/HalfplaneResearch Aug 03 '26
We would benchmark the whole request path, not just FastAPI: event-loop lag, p50/p95/p99 latency, in-flight requests, thread-pool saturation, connection-pool waits, and downstream service latency. Keep CPU-bound work off the event loop, set explicit timeouts and backpressure, then load test with the same payload mix and dependency behavior you see in production.
2
u/addis_yonas Aug 04 '26
Anyone using normal def functions and how high can one set the anyio thread limiter? Default is 40 mine is set to 60. I want to increase it but don’t want to learn the hard way.
1
u/Potential_Ship_1676 Aug 06 '26
It's held up fine for us, the issues are almost always blocking calls sneaking into async endpoints and stalling the event loop rather than FastAPI itself.
1
u/telnet_23 Aug 10 '26
Yeah, in my case, i had to make tons of changes, in memory object caching, cpu bound process offloading to separate process pools, token caching, use of orjson instead of std json module, then async queue listener based logging and offloading sync calls to thread pool executors iif async implementation for those interfaces were not available.
1
u/saadcodes Aug 11 '26
FastAPI in production for 6+ months, ~50k requests/day on a $5/month
Render instance.
The good:
- Async by default means I can handle spikes without touching infra
- OpenAPI docs generated automatically — clients love it
- Pydantic validation catches 90% of bad input before it hits business logic
The reality nobody talks about:
- Default uvicorn is NOT production-ready. You need gunicorn + uvicorn
workers or you'll hit memory leaks
- Without rate limiting, one bad client can take down your entire app.
slowapi or custom middleware is mandatory
- Background tasks (BackgroundTasks) are fine for light work, but anything
heavy should go to a proper queue (I use SQLite + a separate worker
process for MVP stage)
The biggest surprise:
I built a single-file FastAPI app in 3 hours that now processes Excel
conversions. 90 lines. SQLite cache. Stripe integration. $3,600/month
revenue.
The "microservice" crowd would have told me to use Kubernetes, PostgreSQL,
Celery, and a React frontend. I used none of them.
Production doesn't mean complex. Production means it stays up and makes
money.
For high traffic specifically: use gunicorn with uvicorn workers,
enable response compression, and cache aggressively at the application
layer before you reach for Redis.
1
u/bcoder001 Aug 03 '26
Yes, but FastAPI is not the only thing that has to perform on the same level. My client typically use AWS for backed (DynamoDB, S3, Aurora, etc.) to cooe with high levels of traffic.
-6
u/zamroni777 Aug 04 '26
Or you can use multi threads. Create 1 thread for each client session.
https://docs.python.org/3/library/threading.html