Retrying a failed request feels like one of the safest things a system can do. A service times out, so try again. A database briefly rejects a connection, so try again. An API returns 503 Service Unavailable, so wait a moment and make another attempt.
It works often enough that retries become invisible infrastructure. HTTP clients do it, cloud SDKs do it, message consumers do it, and application code wraps network calls in retry helpers. For genuinely short-lived failures that's exactly what we want: a second attempt turns a dropped connection or a process restart into something the user never notices.
But a retry isn't free. Every extra attempt is another request, queue entry, database query or unit of CPU work, sent to a system that may already be failing because it can't keep up. At that point, the mechanism meant to improve reliability can be what's stopping recovery. The Amazon Builders' Library calls retries "selfish" for this reason: each one spends more of the server's time on one caller's chance of success. The Google SRE book describes the same dynamic as a feedback loop that can turn a small overload into a cascading failure.
So the useful question isn't just "should this request retry?" It's "under what conditions is another attempt more likely to help than hurt?" This article works through the pieces that answer it.
Every retry is extra load
Take a service that can handle 10,000 requests per second. Demand rises slightly to 10,100. The service still completes 10,000, and 100 time out. If those 100 retry a second later, the next second sees 10,200 requests, so 200 fail. If those retry too, the next second sees 10,300.
The backend didn't get slower and real users didn't send more traffic. The clients created the extra load themselves.
That's the core idea behind safe retry design: retries aren't just error handling, they generate load. A retry policy decides how patient one request is, but it also decides how much extra pressure clients may put on a dependency while it's failing. Behaviour that looks harmless for one request can be dangerous across a whole fleet.
Which failures are worth retrying
A good retry policy starts with what actually failed. A 400 Bad Request, a 401 Unauthorized, a 503 Service Unavailable and a connection reset aren't the same kind of problem, so a blanket catch { retry(); } treats them all the same when it shouldn't.
| Usually worth retrying | Usually not |
|---|---|
| Connection reset or short network interruption | Invalid request or failed schema validation |
503 Service Unavailable, 504 Gateway Timeout | Invalid credentials (401) or permission denied (403) |
429 Too Many Requests (after waiting) | Resource doesn't exist (404) |
| A brief leader election in a database or broker | Any error that will repeat for the same input |
Sending POST /users with "email": "not-an-email" ten times won't make the address valid. A first-pass classifier might look like this:
function isRetryable(error: HttpError): boolean {
return (
error.status === 429 ||
error.status === 500 ||
error.status === 502 ||
error.status === 503 ||
error.status === 504 ||
error.code === "ETIMEDOUT" ||
error.code === "ECONNRESET"
);
}
Even that isn't universal. A particular 500 might come from a bug that fails every time, and a 409 Conflict might be a short-lived race where retrying is exactly right. Whether something is retryable depends on what the operation and the dependency mean. That's why the AWS SDKs classify errors rather than retrying every exception (their retry behaviour docs cover this).
The question to ask is: if I repeat this exact operation later, is the result likely to change? If not, retrying is just repeated waste.
When you don't know whether it worked
The most dangerous failures are often not the ones where you know an operation failed. They're the ones where you can't tell.
A client sends POST /payments. The server receives it, charges the customer, commits the result and starts sending the response. Then the connection drops. The client sees a timeout, which is consistent with two very different realities: the server never processed the request, or it processed it and the response was lost. Retrying recovers from the first case and double-charges the customer in the second.
Stripe's article on designing APIs with idempotency is built around this problem. The fix is an idempotency key: a stable identifier for the logical operation that the client sends with every attempt, so repeats resolve to the same result instead of creating a new one.
POST /payments
Idempotency-Key: checkout_8ca492_payment
The server stores the key next to the result (here, checkout_8ca492_payment → payment_7421). If the response is lost and the client retries, the server looks up the key and returns the existing payment:
Backoff protects the system's stability; idempotency protects business correctness. Most retry designs need both. A request that's safe to retry from the network's point of view can still be unsafe for the business if repeating it duplicates a payment, booking or message. The Builders' Library goes deeper in Making retries safe with idempotent APIs.
Backoff and jitter
Retrying immediately rarely helps, because whatever caused the failure hasn't had time to change. If a dependency fails at 10:00:00.000 and 10,000 clients retry at 10:00:00.001, the service gets no recovery window at all.
A fixed delay (say, wait one second) only moves the spike. If the requests failed together, they wake up together, and 10,000 failures become 10,000 retries one second later.
Exponential backoff doubles the wait after each failure: 100 ms, then 200, 400, 800, 1,600. Short glitches get a quick second attempt, and sustained failures get progressively less pressure.
function backoff(attempt: number, baseMs = 100) {
return baseMs * 2 ** attempt;
}
But every client runs the same formula. If 50,000 clients fail at about the same moment, they all retry after 1 second, fail together, all retry after 2 seconds, and so on. The waves get further apart but stay just as concentrated.
Jitter adds randomness so clients spread out across the window instead of arriving together. The version below is often called "full jitter": pick a random delay between zero and the capped exponential value.
function retryDelay(attempt: number, baseMs = 100, maxMs = 30_000): number {
const cap = Math.min(maxMs, baseMs * 2 ** attempt);
return Math.random() * cap;
}
Instead of everyone retrying at exactly 4 seconds, attempts are scattered between 0 and 4 seconds:
Jitter doesn't necessarily reduce the number of attempts. It reduces how coordinated they are, which is often what a recovering service needs most. Marc Brooker's Exponential Backoff and Jitter compares the variants with simulations and is worth reading in full.
How retries multiply across layers
Things get much worse when several layers each decide independently that retrying is helpful.
Suppose every layer allows one attempt plus two retries, which sounds conservative. If the database is down, the lowest service tries it 3 times. The service above sees that fail and tries 3 times, each causing 3 database attempts. Across four retrying layers, one user request can turn into 3 × 3 × 3 × 3 = 81 database attempts. With five layers it's 3⁵ = 243.
The Builders' Library article on timeouts, retries and backoff works through exactly this example of a five-deep call stack, and the SRE book also recommends against retrying at every layer.
Deciding which layer retries
That doesn't mean lower layers should never retry. It means someone should decide, on purpose, which layer owns retries. If a high-level operation can safely repeat its workflow and still has time left, it often makes sense for that boundary to own the policy while lower-level calls stay conservative:
HTTP request
↓
Order service ← owns retry policy
↓
Payment service ← no independent workflow retry
↓
Database
A database driver reconnecting after a dropped connection is still fine; lower layers often understand certain failures better than application code does. What you want to avoid is SDK retries, HTTP client retries, service retries, queue retries and load balancer retries all stacking up by accident. A healthy setup can answer three questions: where does the retry policy live, which lower-level retries still exist, and what's the worst-case number of downstream attempts for one user operation? If nobody can answer the last one, retries probably aren't under control.
Deadlines instead of retry counts
maxRetries = 5 says little about what the user experiences. If each attempt can block for 30 seconds, five retries could mean minutes of waiting. Callers usually care about something more like "I need an answer within 2 seconds". That's a deadline, and every attempt, timeout and backoff wait comes out of it:
async function fetchWithDeadline(
operation: () => Promise<Response>,
deadline: number,
) {
let attempt = 0;
while (Date.now() < deadline) {
const remaining = deadline - Date.now();
try {
return await withTimeout(operation(), Math.min(remaining, 500));
} catch (error) {
if (!isRetryable(error)) {
throw error;
}
const delay = retryDelay(attempt++);
if (Date.now() + delay >= deadline) {
throw error;
}
await sleep(delay);
}
}
throw new Error("deadline exceeded");
}
Now retries are part of the caller's latency contract instead of an independent loop. This matters across service boundaries too. If the client gives up after 2 seconds while a downstream service keeps retrying for 20, the work may eventually succeed, but nobody is there to receive the result. I wrote more about this in Who owns the deadline in a chain of microservice calls?.
Timeouts that create failures
Timeouts protect callers from slow dependencies, but a timeout set too tight creates failures the dependency never would have. Suppose normal latency is:
| Percentile | Latency |
|---|---|
| p50 | 80 ms |
| p95 | 180 ms |
| p99 | 420 ms |
| p99.9 | 900 ms |
With a 200 ms timeout, a few percent of perfectly healthy requests get cut off. If those are retried, the extra traffic pushes latency up, which causes more timeouts, which cause more retries. The client has built another feedback loop.
The Builders' Library describes a real case of this. A service's timeout covered setting up a new connection as well as the request, and connection setup took longer than the 20 ms timeout. After deployments, when new servers came into service, a small number of requests timed out. The first fix was to raise the timeout; the better fix was to establish connections when the process started, before it received traffic.
Timeout values should come from measured latency and business deadlines, not intuition. A timeout decides when "slow" becomes "failed", and if failures retry automatically, it also decides when the caller starts generating extra load.
Overload is not the same as a random failure
Two requests can both end in a timeout for very different reasons. In one, a packet was lost while the server was healthy: a retry will probably succeed and costs little. In the other, the database is at 100% CPU, queues are full and every request takes seconds: a retry probably fails and costs a lot. The client sees "timeout" both times.
That's why an overloaded service should say so when it can:
HTTP/1.1 429 Too Many Requests
Retry-After: 5
The server usually knows more about its own recovery than its callers do, so honouring Retry-After beats thousands of clients each guessing when to come back. When failure is random and isolated, another attempt is cheap and useful. When it's systemic overload, another attempt competes with the work that could have succeeded.
Retry budgets
Backoff controls when a retry happens. A retry budget controls how much extra traffic retries may generate in total. For example, a process handling 10,000 successful requests a minute might allow at most 500 retries a minute. Once that's used up, failures are returned straight away instead of retried.
The SRE book recommends this, with the example of allowing only 60 retries per minute per process. The AWS SDKs use a related mechanism, a retry quota backed by a token bucket: retries spend tokens, successes refill them, and a widespread failure drains the bucket so clients start failing fast.
This shifts the question from "has this request retried enough?" to "has this process generated too much retry traffic?" Outages are system-level events, so it helps to have at least one control that thinks at the system level. A budget lets a client say: another attempt might help this request, but the dependency can't afford all of us making that choice right now.
Rejecting work on purpose
Failing requests deliberately feels uncomfortable, but during overload, trying to process everything can mean less work succeeds overall. If a service can handle 10,000 requests per second and receives 14,000, accepting all of them can lead to growing queues, memory pressure, timeouts, retry storms and eventually collapse. Rejecting the extra 4,000 quickly can let the other 10,000 finish.
This is load shedding. A fast rejection is often healthier than a slow timeout, because a slow failure keeps holding resources while the caller waits, and every layer above it waits, times out and retries too. The SRE book's production services best practices recommend dropping a fraction of traffic, retries included, once total load exceeds capacity.
Where circuit breakers fit
A circuit breaker watches for failures and temporarily stops calling a dependency that looks unhealthy. It's usually described with three states:
Circuit breakers are useful, but they bring their own tuning questions: what failure rate opens the circuit, how long it stays open, how many probe requests to let through, and what happens when one instance sees failures and another doesn't. The Builders' Library notes that circuit breakers add modal behaviour that's hard to test and can slow recovery, and that Amazon often limits retries locally with a token bucket instead.
None of this makes circuit breakers bad. It's worth being clear about what each tool does, because they're easy to lump together as "resilience":
| Mechanism | What it controls |
|---|---|
| Backoff | When the next attempt happens |
| Jitter | How spread out attempts are across clients |
| Retry budget | How much retry traffic is generated in total |
| Circuit breaker | Whether calls reach the dependency at all |
| Load shedding | How much work the server accepts |
They complement each other but aren't interchangeable.
Retries in queues
Retry storms aren't limited to HTTP. Picture a worker reading from a queue and writing to a database. The database goes down, a job fails, the queue retries it, it fails again, and so on. With thousands of jobs and a short retry delay, the queue becomes a durable traffic generator aimed straight at the failed dependency, while fresh jobs keep arriving and compete with old failing ones for the same workers.
A queue changes the timing and durability of retries but doesn't make them harmless. The same controls apply: bounded attempts, backoff, jitter, throttling that's aware of the dependency, and a dead-letter queue (somewhere for jobs to go once automatic retries are exhausted, so a person or a reconciliation process can deal with them). A queue consumer needs a way to admit that automatic recovery didn't work.
Measuring retries separately from demand
Retries also distort dashboards. If 1,000 user operations produce 1,700 backend attempts and you only chart backend requests per second, it looks like demand rose 70%. It didn't. The system generated those 700 requests itself.
It helps to count logical operations and attempts separately:
operations_started_totalattempts_totalretries_total,retry_success_total,retry_exhausted_totalretry_budget_exhausted_totaltimeout_totalrequests_shed_total
From those you get a retry amplification factor: total attempts divided by logical operations. 17,000 attempts for 10,000 operations is 1.7×. In normal operation it might sit around 1.01×; during an incident it might jump to 2.8×. Now a traffic spike can be split into real demand and self-generated retries. The SRE book specifically mentions watching retry rates during cascading failures, because otherwise retries look like a symptom when they're actually a cause.
Putting it together
For a typical service-to-service call, I want the retry decision to answer five questions in order:
- Is the failure plausibly temporary? If it will fail the same way again, return the error.
- Is the operation safe to repeat? Either it's naturally idempotent (a
GET, aPUTof a desired state, deleting something already deleted) or there's protection such as an idempotency key or a deduplication record. - Is there enough time left? A retry whose result can't reach the caller is wasted work.
- Is there retry budget left? One caller shouldn't be able to add unlimited load because its request keeps failing.
- When should the next attempt happen? Use capped exponential backoff with jitter.
The important change is that a failure doesn't automatically mean a retry. It starts a decision.
Patterns to avoid
These are the patterns I look for first, because each one removes a control that keeps retries bounded:
- Retrying forever. A
while (true)loop around a call means the system can never admit that automatic recovery failed. - Retrying every error. Permanent failures turn into repeated load.
- Retrying immediately, over and over. The dependency never gets a window to recover.
- Retrying at every layer. Attempts multiply as the request travels down the stack.
- Retrying after the caller has gone. A 30-second backend retry loop behind a 2-second client timeout spends resources on a result nobody will read.
- Retrying side effects without idempotency. A timed-out money transfer that gets blindly repeated becomes duplicate business state.
None of these needs a complicated system to appear. They come from a handful of reasonable-looking defaults that were never designed together as one policy.
Key takeaways
- Treat every retry as extra load on a system that may already be struggling, and give each logical operation a bounded number of attempts.
- Retry only failures likely to change on a second try, and only operations that are safe to repeat. Use idempotency keys for side effects.
- Use capped exponential backoff with jitter so large numbers of clients don't retry in sync, and honour
Retry-Afterwhen the server sends it. - Decide which layer owns retries and know the worst-case number of downstream attempts for one user request.
- Bound retries by the caller's deadline, not just a count, and set timeouts from measured latency.
- Add a retry budget, shed load when you're over capacity, and track retry amplification separately from real demand.
References
- Amazon Builders' Library — Timeouts, retries, and backoff with jitter — choosing timeouts, why retries are "selfish", retry multiplication across layers, and local retry limiting with a token bucket.
- AWS Architecture Blog — Exponential Backoff and Jitter — why synchronized backoff still causes contention, with simulations comparing jitter strategies.
- Google SRE Book — Addressing Cascading Failures — overload as a feedback loop, randomized backoff, retry budgets and where to put retries.
- Google SRE Book — Production Services Best Practices — shedding traffic, including retries, once load exceeds capacity.
- Stripe — Designing robust and predictable APIs with idempotency — ambiguous network failures and how idempotency keys make retries safe.
- AWS SDKs and Tools — Retry behavior — error classification, backoff, and the retry quota (token bucket) used by AWS SDKs.
- Amazon Builders' Library — Making retries safe with idempotent APIs — server-side design that keeps repeated attempts from duplicating business effects.
