FastAPI Adds Concurrency Limits Where Resources Live
FastAPI 0.163.0 adds dependency concurrency limits. Understand resource lifetimes, shared limits, and worker-level capacity before using them.
An asynchronous API can accept work much faster than its database, inference service, or document parser can finish it. Once those resources saturate, allowing more handlers to run often just moves the queue somewhere harder to observe.
FastAPI 0.163.0, released on November 14, 2026, adds Depends(max_concurrency=...). It gives engineers a place to express a resource concurrency budget inside the dependency graph. The useful part is how that budget follows a dependency's lifetime. Getting that lifetime wrong can produce a perfectly valid configuration that protects the wrong stretch of work.
What Happened
The 0.163.0 release introduces dependency concurrency limits through PR #16746. The official release notes independently record the same feature and November 14 publication date.
A dependency can now specify a positive integer limit. When its available slots are occupied, another invocation waits; that waiting does not consume a worker thread. The parameter reference documents the behavior and the default, None, which leaves dependency concurrency unrestricted.
This is a small API change with practical consequences for services that already express resource acquisition through dependencies. It lets a resource provider carry an explicit usage budget alongside the code that creates and releases that resource.
There is no reason to expect an automatic throughput improvement from adding the parameter. The question is whether controlling admission earlier produces more predictable behavior when demand exceeds capacity.
Why It Matters
Consider a retrieval API that performs a database lookup and then calls an external model. A burst of requests can leave many handlers waiting for database access before any useful model work begins. Increasing the application's ability to accept requests does not expand the database's capacity.
My preference is to make the scarce resource visible in the application's design. A dependency that acquires a resource is a natural place to state how many concurrent users of that resource the service should admit.
That creates a useful review question: what exactly does this slot represent? It might represent an open database session, an occupied renderer, or a handler permitted to submit work to a downstream service. Those have different lifetimes and different capacity constraints.
Concurrency also needs to be separated from request rate. Suppose ten operations occupy slots for two seconds each. Ignoring overhead and uneven durations, that budget permits roughly five completions per second. If each operation takes twenty seconds, the same budget permits roughly half a completion per second. These are illustrative calculations, not FastAPI benchmarks.
A fixed concurrency budget therefore cannot, by itself, express a provider's requests-per-minute allowance or token budget. It controls simultaneous occupancy. A service may need separate controls for arrival rate, spending, and queue length.
For agent-facing APIs, this distinction matters because one user action can generate several tool requests. Sizing capacity from interactive user count alone can miss the bursts produced by retries, parallel tool calls, and background work.
How It Works
The central rule is lifetime. For an ordinary dependency, the slot ends when the dependency function returns. With a yield dependency, it remains occupied until teardown completes. The implementation's documentation changes also distinguish scopes: function teardown happens before response transmission, while the default request scope extends through response sending.
Imagine a dependency that simply returns a client object. If the route uses that client later, limiting the dependency's brief execution does not necessarily limit the downstream operation. A resource guard should surround the interval that consumes capacity.
Sharing is equally explicit. The dependency reference says the same Depends() object shares a limit, while separately constructed objects have independent limits, even for the same callable. Limits are separate across event loops and worker processes; reusing a cached dependency value within one request does not count as another invocation.
The deployment implication is easy to overlook. In an illustrative deployment with three replicas, four workers per replica, and a local limit of five, the combined ceiling is sixty occupied slots. That calculation assumes every worker is active and each request occupies one slot. It is a capacity-planning estimate, not a global enforcement mechanism.
Place the limit at acquisition. FastAPI resolves sub-dependencies before applying the parent's limit, as the advanced guide explains. The guide also warns about resource-ordering deadlocks and repeated uncached acquisition. A request can wait forever if it asks for another slot while holding the only slot until request completion.
I would review the resource graph before choosing the integer. Draw which resources remain held while another is acquired. If two execution paths acquire them in opposite orders, reducing concurrency may expose the cycle sooner. It does not remove the cycle.
Example
Here is a self-contained illustration for FastAPI 0.163.0. It uses simulated work so the resource boundary is visible without introducing a database driver or model SDK. It is an explanatory example, not a measured performance result.
import asyncio
from collections.abc import AsyncIterator
from typing import Annotated
from fastapi import Depends, FastAPI
app = FastAPI()
async def processing_slot() -> AsyncIterator[None]:
yield None
ProcessingSlot = Annotated[
None,
Depends(
processing_slot,
max_concurrency=2,
scope="function",
),
]
@app.post("/extract")
async def extract(_slot: ProcessingSlot):
await asyncio.sleep(0.25) # Simulated downstream operation.
return {"operation": "extract", "status": "complete"}
@app.post("/summarize")
async def summarize(_slot: ProcessingSlot):
await asyncio.sleep(0.25)
return {"operation": "summarize", "status": "complete"}Both routes use one alias containing one dependency declaration. The guard yields before the handler performs work and exits after the handler finishes. That shape makes the intended protected interval clear: processing inside either handler consumes the shared local budget.
In a single worker and event loop, the intended observation under overlapping calls is two handlers inside their simulated operation while additional calls wait. To check this in a real service, instrument entry and exit around the protected work and record the peak active count. Then send concurrent requests to both routes, rather than testing each route in isolation.
The deliberately empty guard is useful for explaining admission. In production, I would prefer the actual resource provider to own the limit when practical. That keeps the budget attached to resource use and reduces the chance that a new route bypasses a separate guard.
The scope choice also deserves review. These handlers return small completed results, so the example protects processing through handler completion. A streaming implementation would need a different lifetime analysis: determine whether the scarce resource remains occupied while the response is consumed, then choose the dependency scope accordingly.
Finally, the number two is arbitrary. Derive a production value from downstream capacity and the service's deployment topology. Include consumers outside this dependency, such as scheduled jobs and administrative requests, when calculating the available budget.
My Take
This is a useful addition because it makes a resource budget inspectable in ordinary application code. A reviewer can see acquisition, lifetime, and concurrency policy together. That is easier to reason about than discovering an undocumented semaphore hidden inside a helper.
But I would resist adding limits everywhere. Multiple layers of queues make overload harder to diagnose. A request might wait at ingress, then inside a dependency, then in a connection pool, and finally at a downstream provider. Each queue can look harmless individually while their combined delay exceeds the caller's deadline.
Start with one known bottleneck. Measure its occupancy and the time requests spend waiting to reach it. Compare those measurements with end-to-end latency and completion rate. If occupancy stays pinned at the limit while waiting grows, the service needs an explicit overload decision: accept the delay, reduce incoming work, or add capacity.
I would also distinguish local protection from fleet policy in configuration names and operational documentation. Autoscaling changes the aggregate concurrency budget when every new worker receives its own allowance. A resource shared by the entire fleet needs capacity planning or coordination at that broader scope.
Before rollout, verify cancellation and failure behavior around the actual resource. A happy-path load test cannot tell you whether an interrupted request releases its connection promptly or whether teardown stalls behind another dependency. The important outcome is recovered capacity after unsuccessful work.
Conclusion
FastAPI 0.163.0 brings concurrency policy into dependency declarations. Its practical value depends on placing the limit around the resource's real occupancy interval and accounting for every worker that receives an independent budget.
For an existing service, begin with a constrained resource whose lifetime you can explain precisely. Define its budget, observe waiting and occupancy under load, and check the aggregate allowance after scaling. The parameter is simple; the resource model still needs engineering judgment.