One of the most frustrating performance bugs in Python web services is the endpoint that feels completely fine when you hit it with curl during development, then falls off a cliff the moment 20 users hit it at once.
In FastAPI, this usually happens when two quiet mistakes stack on top of each other inside an async def route:
An N+1 query pattern using a synchronous database driver that blocks the asyncio event loop on every iteration.
Synchronous CPU work (hashing, signing, PDF/JSON crunching) executed directly on the event loop thread.
In this post, we will build a small, zero-Docker FastAPI service instrumented with OpenTelemetry, reproduce the concurrency collapse locally, inspect the trace waterfall, and verify the fix with both unit tests and a 20-request concurrent benchmark.
All code in this article is runnable locally with Python 3.12 and SQLite.…