r/FastAPI • u/Ok-Platypus2775 • Jan 25 '26
Question FastAPI production architecture: modular design and dependency injection best practices
I am new to FastAPI. I have previously worked with Django and DRF. Django feels very well organized and mature, but in my experience it can be slow in some areas and has noticeable performance bottlenecks for certain workloads.
Because of that, I want to give FastAPI a serious try. I am looking for guidance on production level FastAPI architecture.
Specifically:
- How to structure a FastAPI project in a modular way
- Best practices for dependency injection
- How people organize routers, services, and database layers in real world apps
- Any common pitfalls when moving from Django/DRF to FastAPI
If you have examples, repo links, or lessons learned from running FastAPI in production, I would really appreciate it.
58
Upvotes
View all comments
Show parent comment
2
u/jimjkelly Jan 26 '26
We actually saw it go a step further and it was constant performance problems. People accidentally including blocking calls (sometimes even via a dependency), sometimes even serializing large amounts of data, all blocking the event loop and tanking overall system performance. The worst part though is by most observability it looks like the server performed well at p99 - because individual requests are “served” fast. But if you are using external things like envoy you can see the server is so delayed in starting the request the real handle time at p99 is way worse.