Timeouts, Retries and Backoff: Failing Fast Without Causing a Retry Storm
At 14:02 the inventory database fails over to a replica. The failover takes 20 seconds, which the team has tested and is proud of. The incident lasts 50 minutes.
During those 20 seconds every call from the checkout service to inventory fails. The checkout service retries each call 3 times. So does the API gateway in front of checkout, and so does the mobile app in front of the gateway. When the new primary comes up, it receives 27 times its normal load in one wave, because every retry from every layer was scheduled on the same fixed 1 second interval. It falls over. The retries continue. By the time someone disables retries at the gateway, the database has been overloaded for 48 minutes by traffic that no user is still waiting for.
The original fault was 20 seconds long. The retry policy, written to make the system more reliable, turned it into an outage nearly 150 times longer.
Retries are the most useful and most dangerous reliability tool you have. This article covers how to bound every call with a timeout, when a retry is safe, how to space retries out, and how to stop retries from amplifying the failures they are meant to hide.
What timeouts, retries and backoff are
A timeout is the longest a caller will wait for a response before giving up. A deadline is the same idea expressed as an absolute point in time that travels with the request across services. A retry re-sends a request that failed or timed out, in the hope that the failure was transient. Backoff is the waiting time between retries, usually growing exponentially. Jitter randomises that wait so many clients do not retry at the same instant. A retry budget caps how much extra load retries may add.
Together they form one policy: wait a bounded time, retry only what is safe and likely to succeed, spread retries out, and stop retrying when retries are making things worse.
How it works
Why timeouts are mandatory
Many popular clients wait forever by default. Go’s http.Client has no timeout unless you set one. Python’s requests waits indefinitely without a timeout argument. gRPC calls have no deadline by default. Without a timeout, a dependency that hangs (rather than fails) holds a thread, a connection and memory in the caller for as long as it hangs.
Little’s law shows how fast that adds up: requests in flight equal arrival rate times time in system. At 500 requests per second, a healthy 40 ms dependency means about 20 requests in flight. If it hangs and your timeout is 30 seconds, in-flight requests climb toward 500 x 30 = 15,000, far beyond any thread pool or connection pool. The caller now fails too, even for requests that never touch the broken dependency. A short timeout turns a hang into a fast, contained error.
Kinds of timeout
A single “timeout” setting usually hides several:
| Timeout | Bounds | Typical value |
|---|---|---|
| Connect | TCP plus TLS handshake to establish a connection | A few times the network RTT: 100 ms to 1 s in region |
| Request (read) | Waiting for the response after sending | From the dependency’s latency percentiles |
| Total deadline | Everything, including retries and backoff | From the caller’s own latency budget |
| Idle (keep-alive) | How long a pooled connection may sit unused | Shorter on the client than on the server or load balancer |
Connect timeouts can be short because a handshake either completes in a few round trips or is not going to. A connect failure is also the safest error to retry, because the request was never sent.
Idle timeouts cause one of the most common mystery errors in production. If the server or load balancer closes idle connections before the client does, the client occasionally sends a request on a connection the other side has just closed and gets a reset or a 502. The classic case is a backend whose keep-alive timeout is shorter than its load balancer’s idle timeout: AWS Application Load Balancers default to 60 seconds of idle time, while Node.js HTTP servers default keepAliveTimeout to 5 seconds, so the load balancer reuses connections the backend has already closed. The rule: each hop’s idle timeout must be shorter than the next hop’s, so the side that sends requests always closes first.
Choosing timeout values from percentiles
Set request timeouts from measured latency of the dependency when healthy, not from round numbers. A common starting point is a little above the p99.9, so only about 1 in 1,000 healthy requests times out, and then check that the value fits the caller’s budget. A timeout below p99 means 1% of healthy requests fail and are retried, which adds load and latency for nothing. A timeout of 30 seconds on a dependency whose p99.9 is 200 ms protects nothing.
Revisit the values when the dependency changes, and alert on the timeout rate: a jump in timeouts is often the first visible sign that a dependency is degrading.
Deadline propagation across hops
Per-hop timeouts do not compose. If the edge allows 1 second, and service A calls B with a 1 second timeout, and B calls C with a 1 second timeout, then A can give up on B while B and C are still busy, doing work whose result nobody will read. Under load that wasted work is what pushes the system over.
A deadline fixes this by travelling with the request. The edge sets an absolute deadline; each service computes the remaining time, subtracts a small margin for its own work, and passes that to its downstream calls. gRPC does this natively: the client’s deadline is sent as the grpc-timeout header, servers can read the remaining time, and in Go it lives on context.Context so outgoing calls inherit it (more in REST vs GraphQL vs gRPC). For HTTP services, pass it explicitly in a header and enforce it in middleware.
sequenceDiagram participant E as Edge participant A as Checkout participant B as Pricing participant C as Inventory E->>A: deadline = now + 800 ms Note over A: 60 ms own work A->>B: remaining 740 ms Note over B: 40 ms own work B->>C: remaining 700 ms minus 20 ms margin C--xB: still working at the deadline Note over A,C: deadline passes: every hop cancels and stops work A-->>E: DEADLINE_EXCEEDED in 800 ms, not 3 s
Servers should also check the deadline before starting expensive work. A request that arrives with 5 ms left and needs 50 ms should be rejected immediately, not processed and discarded.
Which errors are retryable
Retry only when two things are true: the operation is safe to repeat, and the failure is likely transient.
Safe to repeat means idempotent. GET, PUT and DELETE are idempotent by HTTP semantics; POST is not unless the API accepts an idempotency key. A timeout after the request was sent is an unknown outcome: the server may have completed the work. Retrying a non-idempotent payment after a timeout is how customers get charged twice. That is why idempotency is a prerequisite for retries, not an optional extra.
Likely transient depends on the error:
| Signal | Retry? | Notes |
|---|---|---|
| Connect refused, DNS failure, connect timeout | Yes | Request never sent; safe even for POST |
| Connection reset or read timeout after sending | Only if idempotent | Outcome unknown |
| 502, 503, 504 | Yes, if idempotent | Classic transient failures; honour Retry-After on 503 |
| 500 | Cautiously, if idempotent | Often a bug that will fail again; count against a budget |
| 429 Too Many Requests | Yes, after Retry-After | Retrying sooner makes the throttling worse |
| 408 Request Timeout | Yes, if idempotent | Server gave up waiting for the request, often on an idle connection |
| 409 Conflict | Not blindly | If it means “same idempotency key still in flight”, retry after a delay. If it is a state or version conflict, re-read first |
| Other 4xx (400, 401, 403, 404, 422) | No | The same request will fail the same way |
| gRPC UNAVAILABLE | Yes | The standard transient code |
| gRPC DEADLINE_EXCEEDED | Usually no at this hop | The caller’s time is gone; retrying cannot help it |
| gRPC RESOURCE_EXHAUSTED | Yes, with long backoff | Quota or overload |
Retry-After is the server telling you when to come back, as a number of seconds or an HTTP date, on 429 and 503 responses. Respect it as a minimum delay, but cap it at your own deadline; if the server says 120 seconds and the user is waiting, fail now.
Exponential backoff and jitter
Retrying immediately, or after a fixed delay, sends the retry into the same overload that caused the failure. Exponential backoff grows the wait with each attempt: delay = min(cap, base x 2^attempt). With a 100 ms base: 100, 200, 400, 800 ms, then capped.
xychart-beta title "Maximum backoff before each retry (base 100 ms, cap 5 s)" x-axis ["retry 1", "retry 2", "retry 3", "retry 4", "retry 5", "retry 6", "retry 7"] y-axis "Delay (ms)" 0 --> 5200 bar [100, 200, 400, 800, 1600, 3200, 5000]
Exponential backoff alone has a flaw: clients that failed together retry together. If 1,000 clients fail at t = 0, all 1,000 retry at 100 ms, then all again at 300 ms, and so on, each wave as big as the first. Jitter randomises each delay to break the synchronisation. Marc Brooker’s post “Exponential Backoff And Jitter” on the AWS Architecture Blog compared three variants:
- Full jitter:
sleep = random(0, min(cap, base x 2^attempt)). Spreads retries across the whole window. - Equal jitter: half fixed, half random:
temp = min(cap, base x 2^attempt), thensleep = temp / 2 + random(0, temp / 2). Never retries very early, but clusters more. - Decorrelated jitter:
sleep = min(cap, random(base, previous_sleep x 3)). Each delay depends on the previous one rather than the attempt number.
In the post’s simulation, full and decorrelated jitter completed the work with the fewest total calls, equal jitter was slightly worse, and exponential backoff without jitter was far worse. Full jitter is the simplest good default.
Try it below. Start with 200 clients and server capacity of 20 per 100 ms, and compare the three panels: no backoff hammers the server in repeated spikes, plain exponential backoff still arrives in synchronised waves, and full jitter flattens the load so more clients succeed with fewer total calls. Then lower the max retries to 2 and see how many clients give up under each strategy.
Retry amplification across layers
Retries multiply across layers. If each of d layers makes up to a attempts (1 original plus a minus 1 retries), the deepest dependency can see up to a to the power d attempts for one user action.
flowchart LR
U["1 user action"] --> APP["Mobile app<br/>3 attempts"]
APP -->|"3 calls"| GW["Gateway<br/>3 attempts each"]
GW -->|"9 calls"| SVC["Checkout<br/>3 attempts each"]
SVC -->|"27 calls"| DB[("Inventory DB<br/>already failing")]
style U fill:#F1EFE8,stroke:#888780,color:#444441
style APP fill:#FAEEDA,stroke:#854F0B,color:#633806
style GW fill:#FAEEDA,stroke:#854F0B,color:#633806
style SVC fill:#FAEEDA,stroke:#854F0B,color:#633806
style DB fill:#FCEBEB,stroke:#A32D2D,color:#791F1F
Three layers with 3 attempts each is 3 x 3 x 3 = 27 times the load, arriving exactly when the bottom dependency is least able to take it. With “3 retries” meaning 4 attempts per layer, it is 4 x 4 x 4 = 64.
The fixes are structural:
- Retry at one layer. Usually the layer closest to the failing dependency, which knows whether the error is transient. Layers above it should not retry the same failure again.
- Signal “do not retry”. When a service has already retried and failed, or is overloaded, return a status that tells callers not to retry (a 503 with a long
Retry-After, or a non-retryable gRPC code) instead of a generic error. - Use retry budgets so that even a misconfigured layer cannot multiply load without limit.
Retry budgets and token bucket quotas
A per-request retry limit (“up to 3 attempts”) bounds the damage to one request but not to the system: if every request is failing, every request still makes 3 attempts and load triples. A retry budget bounds retries as a fraction of traffic. A common form: retries may add at most 10% to the request rate of this client. When the dependency is mostly healthy, the budget is never reached and individual failures are retried. When it is failing broadly, the budget runs out and extra load stays near 10% instead of 200%.
The usual implementation is a token bucket in the client:
- AWS SDKs, standard retry mode: a default of 3 total attempts, exponential backoff with jitter, and a retry quota that starts at 500 tokens. Each retry spends tokens and the SDK stops retrying when the bucket is empty; tokens come back as requests succeed. In May 2026 AWS announced updated defaults across its SDKs, which it said would become the default in November 2026: a transient-error retry costs 14 tokens (up from 5), a throttling retry costs 5, and base backoff is 50 ms for transient errors and 1,000 ms for throttling errors.
- gRPC retry throttling: the client keeps a token count starting at
maxTokens. Each failed call subtracts 1, each success addstokenRatio, and retries are only allowed while the count is above half ofmaxTokens. - Envoy supports a retry budget expressed as a percentage of active requests, as an alternative to a fixed maximum number of concurrent retries.
Hedged requests
A hedge is the opposite of a retry for latency, not errors: if a request has not answered by roughly its p95 latency, send a second copy to another replica and use whichever answers first. In “The Tail at Scale” (Dean and Barroso, 2013), a Bigtable benchmark that hedged after a 10 ms delay cut the 99.9th percentile latency for reading 1,000 keys from 1,800 ms to 74 ms while sending only 2% more requests. Hedge only idempotent reads, cancel the loser, and put hedges under the same budget as retries.
Metastable failures
The opening incident is a metastable failure, a term from Bronson and colleagues (HotOS 2021). A system runs fine in a stable state; a trigger (a failover, a deploy, a traffic spike) pushes it into overload; and a sustaining effect keeps it overloaded after the trigger is gone. Retries are the most common sustaining effect: overload causes timeouts, timeouts cause retries, retries keep the load above capacity. Cold caches after a restart are another.
The widget below shows why the effect is so strong near capacity. Latency in a queue grows non-linearly with utilisation. Push utilisation from 70% to 90% and then to 99%: a system at 70% that receives 30% extra retry traffic is at 100%, where latency is unbounded, so more requests time out, which produces more retries.
Getting out requires removing load, not adding capacity slowly: retry budgets that cut retries automatically, load shedding that rejects excess work cheaply, and circuit breakers that stop calling a dependency that is clearly down.
Worked examples
Where it breaks
Retrying non-idempotent writes. A read timeout on a POST is an unknown outcome. Without an idempotency key, the retry may double the effect.
Timeouts longer than the caller’s timeout. If the gateway gives up at 5 seconds and the service calls its dependency with a 10 second timeout, every slow request does up to 5 seconds of work nobody receives. Downstream timeouts must be shorter than upstream ones, which is exactly what deadline propagation enforces.
Retries at every layer. The 27x problem. Decide which layer owns retries for each dependency and turn them off elsewhere.
No jitter. Synchronised retries turn a brief blip into periodic load spikes, especially after a mass disconnect such as a deploy or a failover.
Retrying errors that cannot succeed. Retrying 400, 403 or 422 wastes capacity and delays the error the user needs to see.
Ignoring Retry-After. A throttled client that retries on its own schedule gets throttled again and pushes the server further into overload.
Client libraries with hidden retries. Many SDKs, service meshes and load balancers retry on your behalf. Stacked on your own retries, they produce amplification you did not configure. Audit every layer, including the mesh (see service discovery and service mesh).
Real-world systems
- AWS SDKs ship standard and adaptive retry modes with exponential backoff, jitter and a token bucket retry quota, and published updated defaults in 2026 as described above.
- gRPC supports per-method retry policies (max attempts, backoff, retryable status codes) and retry throttling in its service config, plus hedging policies.
- Envoy route configuration includes per-try timeouts, retry conditions (such as
5xx,reset,connect-failure,retriable-4xx), retry backoff, and retry budgets. Its default route timeout is 15 seconds, which is far too long for many internal calls. - The AWS Builders’ Library article “Timeouts, retries, and backoff with jitter” describes retrying at a single layer and using token buckets to limit retries, and the AWS Architecture Blog’s “Exponential Backoff And Jitter” is the standard reference for jitter variants.
How to apply it
A default policy for a synchronous call between services:
- Set a connect timeout of a few RTTs and a request timeout just above the dependency’s healthy p99.9.
- Propagate a deadline from the edge, and never let a downstream timeout exceed the remaining deadline.
- Retry only idempotent operations (or POSTs with an idempotency key), and only on transient errors: connect failures, 502, 503, 504, 429 after Retry-After, gRPC UNAVAILABLE.
- Use exponential backoff with full jitter: base 50 to 100 ms, cap a few seconds, at most 2 retries.
- Retry at one layer per dependency. Others fail fast.
- Add a retry budget (about 10% extra load) or token bucket quota so retries shut off during broad failures.
- Honour Retry-After, capped by your deadline.
- Monitor timeout rate, retry rate and budget exhaustion per dependency, and alert when retries exceed a few percent of traffic.
Interview angle
Interview questions
Q1: A downstream service is returning 503s. Your service, the gateway and the client SDK all retry 3 times. What happens and what do you change?
Load multiplies across layers: 3 attempts at each of 3 layers is up to 27 requests to the failing service per user action, so the service that is already overloaded gets far more traffic and cannot recover, and users wait through every retry. Fix it by retrying at one layer only, usually the service closest to the dependency; the gateway and SDK should not retry errors that have already been retried, and the service should return a non-retryable signal (a 503 with Retry-After, or a distinct code) once it has given up. Add exponential backoff with full jitter so retries do not arrive in waves, and a retry budget or token bucket so retries are capped at about 10% extra load during broad failures. A circuit breaker can stop calls entirely while the dependency is down.
Q2: How do you choose a timeout for a call to a dependency?
Measure the dependency’s healthy latency distribution and set the request timeout a little above its p99.9, so roughly 1 in 1,000 healthy calls times out. Then check it against the caller’s budget: the caller’s deadline minus its own work must cover the timeout plus any retry and backoff. Set the connect timeout separately, short, at a few round trips. Propagate the deadline so downstream calls never wait longer than the caller will. Long round-number timeouts like 30 seconds are dangerous because, by Little’s law, a hanging dependency then fills the caller’s threads and connections with requests nobody is waiting for.
Q3: Is it safe to retry a POST that timed out?
Not by default. A timeout after the request was sent means the outcome is unknown: the server may have processed it and the response was lost. Retrying can create a duplicate order or charge. It becomes safe if the API supports idempotency keys: the client generates a key once per logical operation, sends it on every attempt, and the server stores the first result and returns it for duplicates. A connect failure, where the request never left the client, is safe to retry even without a key.
✅ Key takeaways
- Every remote call needs a timeout. Default clients often wait forever, and by Little’s law a hanging dependency then exhausts the caller’s threads and connections.
- Set request timeouts just above the dependency’s healthy p99.9, use short connect timeouts, keep idle timeouts shorter than the next hop’s, and propagate deadlines so downstream work stops when the caller gives up.
- Retry only idempotent operations on transient errors (connect failures, 502, 503, 504, 429 after Retry-After, gRPC UNAVAILABLE). Never retry 400, 403 or 422.
- Use exponential backoff with full jitter. Without jitter, clients that failed together retry together.
- Retries multiply across layers (3 attempts at 3 layers is 27x). Retry at one layer, cap retries with a budget or token bucket, and treat retries as the main cause of metastable failures.
🧠 Check your understanding
0 / 4-
1Three layers each make up to 3 attempts per call. How many requests can reach the bottom dependency for one user action?
Attempts multiply: 3 x 3 x 3 = 27. Adding them (3 + 3 + 3 = 9) is the common mistake; each attempt from an upper layer triggers the full retry sequence of the layer below.
-
2Why add jitter to exponential backoff?
Exponential growth already makes waits longer. Without randomness, clients that failed together keep retrying together, so each wave is as large as the original spike. Jitter spreads them out.
-
3Which response should generally not be retried with the same request?
A 422 means the request failed validation, so the identical request will fail again. 503 and 429 are transient and tell you when to retry, and a refused connection means the request was never sent.
-
4A service's p99.9 latency is 200 ms. Its caller uses a 30 second timeout. What is the main risk?
By Little's law, in-flight requests equal rate times wait. A 30 s wait at a few hundred requests per second means thousands of stuck requests, so the caller fails too. Too many timeouts would be the problem with a timeout set below p99, not far above it.
Where to go next
- Idempotency: the server-side mechanism that makes retrying writes safe.
- Rate limiting algorithms: the token bucket behind retry quotas, and what clients should do with 429 and Retry-After.
- Circuit breaker: stop calling a dependency that is clearly down, instead of retrying it.
- Bulkheads, load shedding and backpressure: the other half of escaping a metastable failure.
Finished this lesson?
Mark it complete to track your progress across the roadmap.