Your FastAPI endpoint works perfectly when you test it alone. Under concurrent traffic, requests finish one after another. A slow report blocks a lightweight endpoint. CPU usage may look normal, yet response times keep climbing.
Adding async did not fix it. Adding workers helped temporarily, but the slowdown returned.
The first thing to understand is that “one request at a time” describes a symptom, not a diagnosis. Your application might be blocking its event loop, exhausting a thread pool, waiting for database connections, or encountering serialization elsewhere.
Before changing worker counts, find out which resource requests are waiting for.
First, verify that requests actually overlap
Do not diagnose concurrency by repeatedly refreshing one browser tab. Your test must send overlapping requests.
Create a small diagnostic application:
import time
from fastapi import FastAPI
app = FastAPI()
@app.get("/slow")
async def slow():
time.sleep(3)
return {"status": "finished"}
@app.get("/health")
async def health():
return {"status": "ok"}
Run one worker so another process cannot hide the problem:
uvicorn main:app --workers 1
From two terminals, call /slow, then call /health while the slow request is still running.
In this deliberately broken example, /health waits because time.sleep() blocks the thread running the event loop.
Repeat the experiment against your real application using a cheap endpoint. Avoid one that queries a database or calls another service; otherwise, both requests might be waiting for the same downstream dependency.
Use a local or staging environment rather than adding artificial delays to production.
Why async def does not make blocking code asynchronous
An async endpoint runs on the event loop. While one task awaits an operation that yields control, the loop can serve other tasks.
But ordinary synchronous work does not automatically yield.
Calling requests.get(), a synchronous database driver, time.sleep(), or expensive Python computation inside an async endpoint can occupy the event-loop thread.
FastAPI distinguishes between endpoint types:
- An
async defendpoint executes as an asynchronous function. - A normal
defendpoint runs in an external thread pool. - A normal helper function called directly from an async endpoint still executes directly. FastAPI does not automatically move that helper into a thread pool.
That final distinction explains many production surprises. A helper being declared with def does not make it safe to call from async code. [349]
Identify which queue is growing
An application can serve requests concurrently and still appear serialized because all requests need a constrained resource.
Use this table to narrow the investigation:
| Observation | Investigate first |
|---|---|
| A slow endpoint delays an otherwise independent health endpoint | Event-loop blocking or process-level saturation |
| Only database-backed endpoints slow down | Database pool waits, slow queries, or locks |
| Synchronous endpoints slow down while simple async endpoints remain responsive | Thread-pool saturation |
| One external integration causes the slowdown | HTTP connection pool, upstream latency, or rate limits |
| One account or resource is affected | Application locks or database contention |
| Requests never arrive concurrently at the application | Client, proxy, or upstream queueing |
These are clues, not proofs.
Record when a request enters the application, when it starts waiting for a resource, and when useful work actually begins. Total request duration alone cannot tell you which queue is responsible.
Fix 1: use genuinely asynchronous I/O
For the diagnostic example, replace the blocking sleep:
import asyncio
@app.get("/slow")
async def slow():
await asyncio.sleep(3)
return {"status": "finished"}
The request still takes approximately three seconds, but the event loop can process other requests during the wait.
Apply the same principle to real I/O.
If your endpoint makes HTTP requests, use an asynchronous client correctly. If it accesses a database, verify that the driver and calling pattern are actually asynchronous.
Writing await somewhere in the endpoint is not enough. A blocking operation earlier in the function still blocks.
Also inspect dependencies, decorators, authentication helpers, and logging handlers. The blocking work may happen before the visible endpoint body.
Fix 2: move unavoidable synchronous I/O off the event loop
Sometimes the only available integration is a synchronous SDK.
If the entire endpoint is synchronous, a normal def endpoint lets FastAPI execute it through its thread-pool machinery. [349]
If an otherwise async endpoint needs one blocking I/O operation, explicitly offload that operation:
import asyncio
import requests
def fetch_account(account_id: str):
response = requests.get(
f"[https://api.example.com/accounts/{account_id}](https://api.example.com/accounts/{account_id})",
timeout=5,
)
response.raise_for_status()
return response.json()
@app.get("/accounts/{account_id}")
async def account(account_id: str):
return await asyncio.to_thread(fetch_account, account_id)
Python documents asyncio.to_thread() as a way to execute blocking I/O without blocking the event loop. [348]
Notice that the underlying HTTP request has its own timeout. Keeping work off the event loop does not make slow external operations harmless.
Also, confirm that the SDK or shared client is safe to use across threads before changing how it executes.
Fix 3: check thread-pool saturation
Offloading synchronous work protects the event loop, but it creates another finite resource: thread capacity.
Starlette, which FastAPI builds on, uses AnyIO’s thread-pool mechanism for synchronous endpoints and other operations. Its documented default capacity is 40 tokens, shared with other users of that limiter, including synchronous FastAPI dependencies. [351]
That does not mean your entire application supports only 40 concurrent requests. It means operations needing those tokens may queue when the capacity is occupied.
Also, asyncio.to_thread() uses asyncio’s executor machinery; do not assume its capacity and Starlette’s AnyIO limiter are the same setting.
Before increasing thread capacity, inspect:
- How long blocking operations run
- Whether external calls have timeouts
- Whether database connections are available
- Whether the same resource is being accessed repeatedly
- Whether downstream systems can handle additional concurrency
More threads can move the bottleneck into PostgreSQL or an external API rather than eliminate it.
Fix 4: separate CPU work from request handling
Async is useful for overlapping waits. It does not make expensive computation disappear.
Image processing, large document generation, Python-heavy transformations, and model inference can occupy a worker long enough to delay other requests.
For conventional GIL-enabled CPython, moving pure Python CPU work into threads usually does not provide parallel execution of that work. Python documents exceptions for native extensions that release the GIL and implementations without that restriction. [348]
Choose the execution model based on the workload:
- Short computation: keep it bounded and measure its impact.
- Substantial CPU work: consider process-based execution.
- Long-running jobs: consider a durable background-job system.
- Native inference or scientific libraries: understand their own threading and concurrency limits.
Do not assume a background task automatically isolates CPU work from the web process.
Measure event-loop delay, not just request time
A slow endpoint can be waiting normally. A delayed event loop means unrelated tasks cannot resume promptly.
In a controlled debugging environment, enable asyncio debug mode. Python can log callbacks exceeding its slow-callback threshold, which defaults to 100 milliseconds and is configurable through loop.slow_callback_duration. [319]
Use those diagnostics alongside:
- Request latency percentiles
- Event-loop delay
- Database connection-acquisition time
- External HTTP request duration
- Thread-capacity waits
- CPU utilization and container throttling
For short blocking operations repeated frequently, individual slow-callback warnings may not explain the full problem. Profiling and event-loop delay measurements can provide additional evidence.
Why adding workers is not the first fix
More worker processes can provide additional execution capacity. But they can also conceal a blocking endpoint until traffic grows again.
They multiply other resources too:
- Database connection pools
- HTTP client pools
- In-memory caches
- Model copies
- Per-process background work
Before adding workers, check both process memory and downstream connection budgets.
If one request holds a database connection for several seconds, adding workers may increase the number of requests waiting inside the database rather than improve throughput.
Retest the exact failure
After making a change, repeat the same overlapping-request test.
A useful result is not merely that the slow endpoint became faster. It is that



