Artur Keraz’s Post

We almost blamed FastAPI for a performance issue that had nothing to do with FastAPI. A client reported that one endpoint was “randomly slow.” Same code path, same server, same payload shape, but some requests returned in 90ms and others in 2.5 seconds. At first, the team looked at the framework: maybe async overhead, maybe too many dependencies, maybe Pydantic validation. Wrong direction. The real problem was in PostgreSQL. One query used a filter that looked harmless in code, but under load it triggered a sequential scan because the index did not match the actual access pattern. The endpoint only became slow when the table crossed a certain size, which made it feel like an application bug. What fixed it: 1. Logging the slow query, not just the slow endpoint 2. Running `EXPLAIN ANALYZE` on real production-like data 3. Replacing a generic index with a composite index that matched the query 4. Returning less data from the endpoint instead of “just in case” fields Result: response time dropped from 2.5s to 120ms. My takeaway: when an API gets slow, don’t start by blaming the framework. In many cases, the bottleneck is the database, the query shape, or the amount of data you send back. Have you ever spent hours debugging the app layer and then found the real issue in SQL? #FastAPI #PostgreSQL #Python #BackendDevelopment #APIDesign

looks like you don't use monitoring tools

Like
Reply

To view or add a comment, sign in

Explore content categories