Timeout budgets and deadline propagation
Every request has a budget: the time after which the answer is no longer useful. Most systems express that budget as a timeout on each call, which is not the same thing. Three sequential calls with a two-second timeout each can hold a worker for six seconds, and the user left after two.
Deadline, not timeout
A timeout is relative to the moment a call starts. A deadline is an absolute point in time carried with the request. When the caller passes its remaining budget to each callee, every layer knows how much time is actually left, and a slow first hop cannot leave the rest of the chain believing it still has the full allowance.
| Layer | Timeout per call | Remaining deadline |
|---|---|---|
| Edge | 2,000 ms | 2,000 ms |
| API | 800 ms | 1,900 ms |
| Service A | 400 ms | 1,050 ms |
| Database | 150 ms | 600 ms |
Leave room for the response
A deadline that exactly equals the sum of downstream timeouts leaves no time to serialise and return. Reserve ten to twenty percent of the budget for the response path and for retries that may happen near the end. If a retry cannot finish within the remaining budget, do not start it; fail fast and let the client decide.
What happens when a deadline expires
Cancellation must actually stop work. A server that returns 504 but keeps the query running has not saved capacity; it has only hidden the cost. Propagate cancellation to the database driver and to any queued work, and count cancelled requests separately from timeouts so you can see whether expiry is rare or routine.
Testing the budget
Inject a fixed delay into one dependency and watch where the request fails. If the failure appears as a 504 at the edge with no internal warning, the budget is being consumed silently. If it appears as a 500 with a stack trace, the error handling is not distinguishing a timeout from a bug, and every client will treat a transient condition as permanent.
Finally, align the client timeout with the server's. A mobile client that gives up at three seconds against a server budget of five will retry while the first request is still running, doubling load at the worst moment. The outer timeout should always be longer than the inner deadline.
Timeouts in queues and retries
A timeout that starts when a request enters a queue measures the wrong thing. If a request waits 400 milliseconds for a worker and then runs a 600-millisecond query, a 600-millisecond timeout fires immediately when the query starts, even though the work would have finished in time. Propagating a deadline rather than a fresh timeout at each hop keeps the measurement honest and prevents this class of false expiry.
Retries deserve the same care. A retry should check the remaining deadline before it starts, not after it fails. When the remaining budget is smaller than the expected duration of an attempt, failing fast is both cheaper and more honest than starting work that cannot finish. The client can then decide whether to surface the error or try a different path.
- Start the clock at the queue, not at the worker.
- Check the remaining budget before every retry.
- Log the budget at failure so slow paths are visible.
Writing the budget down
Keep the budget in one place — a table in the repository that names each hop, its timeout and its share of the total. When a new dependency is added, the table makes the trade-off explicit: something else must give up time, or the user-facing deadline must grow. Without that table, deadlines are negotiated per pull request and the sum drifts past what the client will wait for.
Open the calculators and put these numbers to work on your own API.
Open API BenchFrequently asked questions
Should every internal call carry a deadline?
Yes, if the protocol supports it. Without one, a callee cannot know that its caller has already given up, and it continues consuming capacity for a result nobody will read.
How many retries fit in a two-second budget?
With a 600 ms attempt timeout and backoff, usually two. If the first attempt takes the full timeout, the second has about 1.4 seconds including backoff, and a third rarely fits.
What status code should an expired deadline return?
504 at a gateway that waited on an upstream, or 503 if the service shed the request deliberately. Include Retry-After only when the condition is genuinely temporary.
Sources
- Google SRE Book — Addressing cascading failures
- RFC 9110 §15.6 — Server errors
- MDN — HTTP response status codes
Related guides
- Capacity planning with Little's LawTurn a target request rate and three latency percentiles into the concurrency, threads and instances an API actually needs.
- Tail latency: why P95 and P99 decide your timeoutAverages hide the requests that hurt. How to read percentiles, calculate what they cost, and set timeouts that do not cut off healthy traffic.
- Retry storms: how a 1% error becomes 300% loadRetries are new traffic. Calculate the amplification, recognise the cliff, and design retry budgets that fail politely.
- REST vs GraphQL: measuring the payload differenceOver-fetching, under-fetching and query text all show up in the bytes. A practical way to compare the transfer volume of both designs.