Tagged articles
1 articles
Page 1 of 1
Code Mala Tang
Code Mala Tang
Jul 1, 2025 · Backend Development

How a Simple Depends() Fix Halved My FastAPI Response Times

After noticing API endpoints taking up to a second, the author discovered that misusing FastAPI's Depends() with a get_db() function that recreated the database engine on each request caused severe latency, and by refactoring get_db() into a proper generator that reuses a single engine, response times were roughly halved.

DependsFastAPIPerformance Optimization
0 likes · 6 min read
How a Simple Depends() Fix Halved My FastAPI Response Times