Retries Without a Retry Storm: Backoff, Jitter and Retry Budgets, Measured

Retrying failed requests is easy to get wrong. We pointed 500 clients at a local Node server during a one-second outage and tried six retry strategies, then tested retry budgets under overload. Here is what each one did, and how to write a retry loop that helps instead of hurting.

Arvind Nishad
·25m read·64 views

A request fails. The obvious fix is to send it again. Most of the time that works: a dropped connection or a busy server is often fine a moment later.

The trouble starts when many clients fail at the same time, which is exactly what happens during an outage, a deploy or a traffic spike. Then every client retries, the server that was struggling now gets two or three times the traffic, and a short blip turns into a long outage. This is called a retry storm.

This post measures the problem instead of describing it. We ran a small Node.js server on one machine, knocked it over for one second, and pointed 500 clients at it with six different retry strategies. Then we overloaded it for five seconds and compared plain retries with a retry budget. Every number below comes from those runs (Node 22.23.4; the test scripts are described as we go), and every example in the post can be run on this page.

It is also a common interview question, usually phrased as "This call to the payment service sometimes fails. How would you add retries?" The interviewer is listening for four words: backoff, jitter, budget and idempotency.

Terms used in this post

  • Retry: sending the same request again after it failed.
  • Backoff: waiting before a retry, usually longer after each failure.
  • Exponential backoff: the wait doubles each time: 100 ms, 200 ms, 400 ms, 800 ms, and so on, up to a cap (a maximum wait).
  • Jitter: a random amount added to (or taken from) the wait, so that clients do not all retry at the same moment.
  • Retry budget: a limit on how many retries a client may send, counted across all its requests, not just one.
  • Idempotent: safe to repeat. Doing it twice has the same effect as doing it once.

Why retries are dangerous

Short answer: A retry spends more of the server's capacity to raise your chance of success. When the server is failing because it is overloaded, every retry makes the overload worse.

Marc Brooker puts it bluntly in the AWS Builders' Library article Timeouts, retries, and backoff with jitter: "Retries are 'selfish.' In other words, when a client retries, it spends more of the server's time to get a higher chance of success."

That is fine when failures are rare and random. One client in a thousand retries, and nobody notices. It is not fine when failures are caused by the server being overloaded, because then every client fails together and retries together. There are two separate problems hiding here:

  1. Timing. If all clients wait the same amount, they all come back at the same instant. The server sees a wall of traffic, rejects most of it, and the clients wait and come back together again.
  2. Volume. Even with perfect timing, three attempts per request means up to three times the traffic, at the exact moment the server can least handle it.

Jitter fixes the first problem. Retry budgets fix the second. We will measure both.

The test setup

The server is about 20 lines of Node. It handles at most 20 requests at once, and each request takes 50 ms of simulated work, so it can serve roughly 400 requests per second. Anything over that limit gets an immediate 503 Service Unavailable. For the first second of each run, it rejects everything, to simulate a crash or a bad deploy.

// The test server (excerpt). It runs in its own process.
let inflight = 0;
http.createServer((req, res) => {
  const now = Date.now() - t0;
  if (now < OUTAGE_MS || inflight >= 20) {   // down, or full
    res.writeHead(503);
    return res.end();
  }
  inflight++;
  setTimeout(() => { inflight--; res.end("ok"); }, 50);  // 50 ms of "work"
}).listen(7070);

In a separate process, 500 clients each send one request at t = 0 and retry every 503. Every strategy uses a 50 ms base delay, a 5 second cap, and at most 10 attempts per client. We ran each strategy three times and report the median.

Six retry strategies, one outage

Short answer: Without backoff, clients burn all their attempts during the outage. Exponential backoff without jitter keeps the clients in lock-step, so only 100 of 500 got through. Any of the jittered strategies served everyone (or nearly everyone) in about 4.5 to 6 seconds.

Here are the six strategies. attempt starts at 0, BASE is 50 ms and CAP is 5,000 ms:

StrategyWait before the next attempt
No backoff0 ms
Fixed100 ms every time
Exponential, no jittermin(CAP, BASE * 2^attempt)
Full jitterrandom(0, min(CAP, BASE * 2^attempt))
Equal jitterhalf of the exponential wait, plus a random amount up to the other half
Decorrelated jittermin(CAP, random(BASE, previous wait * 3))

The last three are the names Marc Brooker gave them in the 2015 AWS Architecture Blog post Exponential Backoff And Jitter, which ran a similar experiment with simulated clients.

What happened:

StrategyClients servedGave upRequests the server receivedLast success
No backoff05005,000never
Fixed 100 ms05005,000never
Exponential, no jitter1004004,80016.4 s
Full jitter50003,5425.3 s
Equal jitter50003,3535.9 s
Decorrelated jitter480203,3734.5 s

Bar chart of clients served out of 500 for each retry strategy: zero for no backoff and fixed delay, 100 for exponential without jitter, 500 for full and equal jitter, and 480 for decorrelated jitter.Bar chart of clients served out of 500 for each retry strategy: zero for no backoff and fixed delay, 100 for exponential without jitter, 500 for full and equal jitter, and 480 for decorrelated jitter.

For scale: the server serves about 400 requests a second, so in a perfect world all 500 clients would be done about 1.25 seconds after the outage ends, at roughly 2.25 s. Nothing gets close to that, and that is normal. Spreading clients out costs some time.

The interesting parts are why each strategy behaved the way it did.

No backoff and fixed delays: done before the server came back

With no backoff, each client fired its 10 attempts as fast as the network allowed. All 5,000 requests arrived in the first 700 ms, inside the one-second outage, and every single one was rejected. The fixed 100 ms delay was no better here: 10 attempts spaced 100 ms apart cover exactly one second, and the outage lasted one second. The server saw a flat 500 requests in every 100 ms window and then silence.

The lesson is not "100 ms is too short". It is that a fixed schedule gives up after a fixed amount of time, whatever is happening on the server. Exponential backoff covers a much longer outage with the same number of attempts: 10 attempts at 50 ms doubling (capped at 5 s) span about 16 seconds.

Exponential without jitter: a thundering herd on a timer

This is the surprising one. All 500 clients failed at the same instant, so they all slept 50 ms, then 100 ms, then 200 ms, and so on, in lock-step. Every retry arrived as a wave of up to 500 requests in the same few milliseconds. The server could take 20 at once, so each wave got 20 through and rejected the rest.

After the outage ended at 1 second, there were exactly five waves left (at about 1.55 s, 3.15 s, 6.35 s, 11.35 s and 16.35 s). Five waves times 20 slots is 100 clients. The other 400 ran out of attempts, even though the server was idle almost the whole time between waves. A crowd that all moves at once is called a thundering herd, and backoff without jitter keeps the herd together.

Jitter: spreading the herd out

Add randomness and the waves dissolve. This small simulation shows where 1,000 clients send their fourth attempt (after three waits), counted in 200 ms buckets. It uses a seeded random number generator so it prints the same thing every time:

Output:

no jitter        0    0    0 1000    0    0    0    0
full jitter    148  498  336   18    0    0    0    0
equal jitter     0    9  840  151    0    0    0    0

Without jitter, all 1,000 clients land in the same bucket (600 to 800 ms). With full jitter, they spread from 0 to 700 ms. Equal jitter spreads them too, but less, because half of each wait is fixed.

Histogram of when 1,000 clients send their fourth attempt: without jitter all 1,000 land in one 200 millisecond bucket; with full jitter they spread across four buckets.Histogram of when 1,000 clients send their fourth attempt: without jitter all 1,000 land in one 200 millisecond bucket; with full jitter they spread across four buckets.

Which jitter is best?

In our run:

  • Full jitter served everyone and was the simplest to write. It sent a few more requests (3,542) than equal jitter, because some of its random waits are very short.
  • Equal jitter served everyone with the fewest requests (3,353) but was the slowest to finish (5.9 s). Keeping half of the wait fixed keeps the clients partly in step.
  • Decorrelated jitter finished fastest (4.5 s) and had the lowest peak, about 660 requests in its busiest 100 ms window against roughly 1,100 to 1,250 for full jitter. But 20 clients gave up: its waits can stay near the 50 ms base for several attempts in a row, and those unlucky clients spent all 10 attempts early.

Brooker's 2015 simulation reached a similar verdict: "The no-jitter exponential backoff approach is the clear loser", and "The decision between 'Decorrelated Jitter' and 'Full Jitter' is less clear." Our results differ from his in the details (in his runs, equal jitter was the loser), which is a good reminder that these numbers depend on the server, the client count and the attempt limit. Use full jitter unless you have measured something better for your system. It is what the AWS SDKs use, and it is one line of code.

One warning: do not assume your HTTP library adds jitter. The default retry delay in undici's RetryHandler (8.10.2, the library behind Node's built-in fetch) is minTimeout * timeoutFactor ** (counter - 1), capped at maxTimeout, with no random part, according to its docs and its source. That is exponential backoff without jitter, the strategy that served 100 of 500 clients above. If you use it under load, pass your own retry function.

Problem two: retries multiply traffic

Short answer: Three attempts per request means up to three times the traffic during an overload. If several layers of a system each retry, the multipliers stack: three layers of three attempts is 27 calls, five layers is 243.

Measured: retries under sustained overload

Jitter fixes when retries arrive. It does nothing about how many. To see that, we sent 600 new requests per second for five seconds (3,000 in total, evenly spaced) to the same server, which can handle about 400 per second. No outage this time; just more traffic than capacity, which is what a busy afternoon or a viral launch looks like.

We compared three client policies, three runs each:

PolicyRequests the server receivedLoad multiplierRequests served
No retries3,0001.00x1,552
Up to 3 attempts, full jitterabout 7,0602.35xabout 1,597
Up to 3 attempts, 10% retry budgetabout 3,3401.11xabout 1,558

Retrying every failure more than doubled the traffic on a server that was already full, and it bought 3% more successful requests. In our test server, a rejection costs almost nothing. In a real service, each rejected request still costs a TLS handshake, request parsing, a log line and maybe an auth check, so that 2.35x extra load would push the server further over the edge, not just waste the client's time.

These numbers line up closely with the Google SRE book's chapter on handling overload, which says that with per-request retries "the number of requests will grow significantly, to somewhere just below 3X", and that a per-client budget "reduces the growth to just 1.1x in the general case."

Retrying at every layer

The problem gets much worse when a request passes through several services and each one retries. Picture a browser calling an API gateway, which calls an order service, which calls an inventory service, which calls a database. If the database is down and every layer makes up to 3 attempts, the attempts multiply at each level:

Output:

1 retrying layer(s): 1 user request -> 3 database calls
2 retrying layer(s): 1 user request -> 9 database calls
3 retrying layer(s): 1 user request -> 27 database calls
4 retrying layer(s): 1 user request -> 81 database calls
5 retrying layer(s): 1 user request -> 243 database calls
5 layers, retry only above the database: 3 database calls

The AWS article gives the same example: "If each layer retries independently, the load on the database will increase 243x, making it unlikely to ever recover." Its advice, and the SRE book's, is to retry in one place. AWS: "our best practice is to retry at a single point in the stack." The SRE book: "requests should only be retried at the layer immediately above the layer that is rejecting them." The other layers should pass the failure up quickly, ideally with a status that says "do not retry this" so the layers above know the retrying already happened.

Five boxes stacked from user request to database: when every layer retries 3 times the calls grow 3, 9, 27, 81, 243; when only the layer above the database retries, the database sees 3 calls.Five boxes stacked from user request to database: when every layer retries 3 times the calls grow 3, 9, 27, 81, 243; when only the layer above the database retries, the database sees 3 calls.

Retry budgets

Short answer: A retry budget caps retries as a share of all requests (for example, 10%), so retries help when failures are rare and switch themselves off when everything is failing.

A per-request limit ("at most 3 attempts") does not know whether one request failed or all of them did. A budget does, because it is shared across all of a client's requests. There are two common designs:

  • Ratio budget. The SRE book describes it: "Each client keeps track of the ratio of requests that correspond to retries. A request will only be retried as long as this ratio is below 10%." That is what our overload test used.
  • Token bucket. gRPC's retry design (proposal A6) keeps a token_count that starts at maxTokens. "Every failed RPC will decrement the token_count by 1." "Every successful RPC will increment the token_count by tokenRatio." When the count falls to half of maxTokens or below, retries stop until it climbs back.

Here is the token bucket in a few lines, with a server that fails the first 200 calls and then recovers:

Output:

During the outage: 203 requests sent for 200 calls (3 retries)
Retries allowed again after 51 successful calls
Tokens after recovery: 10.0 of 10

Two retries on the first call, one on the second, and then the bucket is at half and retries stop. For the rest of the outage the client sends each call once, so the server sees 203 requests instead of 600. Once the server is healthy, 51 successes (at 0.1 tokens each) refill the bucket past the halfway mark and retries come back on their own. Nobody had to flip a switch.

The AWS SDKs do the same thing with a retry quota. The current AWS SDK retry behavior page describes a 500-token budget where each retry costs tokens and successes give them back, a default of 3 attempts (one request plus up to two retries), and full-jitter backoff capped at 20 seconds. That page describes a new version you currently opt into with AWS_NEW_RETRIES_2026=true; the exact token costs differ in the older behavior, so check the page for your SDK before quoting numbers.

A token bucket holding 10 tokens: each failure removes 1 token, each success adds 0.1, and retries are only allowed while the bucket is more than half full.A token bucket holding 10 tokens: each failure removes 1 token, each success adds 0.1, and retries are only allowed while the bucket is more than half full.

What to retry, and what not to

Short answer: Retry failures that might go away on their own (timeouts, connection resets, 429, 502, 503, 504). Do not retry failures that will happen again (400, 401, 403, 404, 422). Only retry requests that are safe to repeat.

FailureRetry?Why
Connection reset or refused, DNS hiccupYesThe network or the server blinked.
TimeoutYes, if the request is idempotentThe server may have done the work and the reply got lost.
429 Too Many RequestsYes, after the Retry-After timeThe server is telling you to slow down.
502, 503, 504YesA proxy or the server is overloaded or restarting.
500 Internal Server ErrorMaybeSometimes a transient bug, often a real one that will fail again.
400, 401, 403, 404, 409, 422NoThe request itself is the problem. Sending it again changes nothing.

Two details that matter a lot in practice:

Honour Retry-After. RFC 6585, which defines 429, says the response "MAY include a Retry-After header indicating how long to wait before making a new request." The value is either a number of seconds or an HTTP date (this is how undici's RetryHandler reads it too). gRPC has its own version, the grpc-retry-pushback-ms header, and A6 says the client "will retry after exactly that delay." The server knows its own state far better than your random number generator does.

Only retry what is safe to repeat. A timed-out GET is harmless to send again. A timed-out POST /charges might already have charged the card. That is why undici's RetryHandler only retries GET, HEAD, OPTIONS, PUT, DELETE and TRACE by default. To retry a POST safely, the server needs an idempotency key, which we covered in detail in Retry It, Charge Once.

A retry helper you can actually use

Putting it together: full jitter, a small attempt limit, a list of retryable statuses, Retry-After support, and an overall deadline so the total time spent retrying is bounded. The demo at the bottom uses a fake server and a fake clock so it runs instantly; in real code you would leave sleep and random at their defaults.

Output:

1. Connection reset, then 503, then success:
  attempt 1 failed (ECONNRESET), waiting 50 ms
  attempt 2 failed (503), waiting 100 ms
  final status 200
2. 429 with Retry-After: 2
  attempt 1 failed (429), waiting 2000 ms
  final status 200
3. 400 Bad Request is not retried:
  final status 400
4. Retry-After: 30 is longer than the deadline, so give up now:
  final status 503

Each case shows one rule: network errors and 503s are retried with growing waits (50 ms, then 100 ms, since the fake random number is always 0.5); a Retry-After: 2 overrides the computed wait; a 400 is returned at once; and a Retry-After longer than the remaining deadline makes the helper give up immediately instead of keeping the user waiting for 30 seconds.

What this helper deliberately does not have is a retry budget, because a budget has to be shared by every request the process makes, not created per call. In a real service you would create one RetryBudget (from the previous section) per downstream dependency and check budget.canRetry() before each sleep.

Timeouts: the other half of retries

A retry can only start after a failure, and a slow server often does not fail; it just takes forever. So every retried call needs a timeout: a limit on how long one attempt may take. In fetch, that is AbortSignal.timeout(ms).

There are two limits to think about:

  • Per-attempt timeout: how long one try may take. Set it from the dependency's normal latency, for example a bit above its 99th percentile, so healthy-but-slow requests are not cut off.
  • Overall deadline: how long the caller is willing to wait in total, across all attempts and waits. If your API promises an answer in 2 seconds, three attempts with 1 second timeouts cannot fit.

A request with a 10 second timeout and 3 attempts can keep a user waiting over 30 seconds. Usually it is better to fail fast and show an error than to hold a connection open that long.

Common mistakes

  • Retrying without jitter. Shown above: it keeps clients in lock-step. In our test, only 100 of 500 clients got through.
  • Retrying at every layer. Five layers of three attempts is 243 calls to the database for one user click.
  • Retrying non-idempotent requests. A retried payment without an idempotency key can charge twice.
  • Retrying errors that cannot succeed. A 400 or 401 will fail the same way every time.
  • No cap on the wait. Doubling from 100 ms reaches over 100 seconds by the 11th attempt. Cap it (a few seconds to 20 seconds is typical) and stop after a few attempts.
  • No overall deadline. The user gave up long ago, but your service is still retrying on their behalf.
  • Trusting library defaults. Check what your HTTP client, SDK or service mesh already does. If both your code and the library retry, you have built two layers of retries without knowing it.

How to answer this in an interview

If you are asked "How would you add retries to this call?", a strong answer covers these points in about a minute:

  1. Decide what to retry: only transient failures (timeouts, connection errors, 429, 502, 503, 504), and only idempotent requests. For a POST like a payment, add an idempotency key first.
  2. Use exponential backoff with full jitter, capped at a few seconds, with a small attempt limit (2 or 3 retries). Without jitter, clients that failed together retry together.
  3. Honour Retry-After when the server sends it.
  4. Limit total retries with a budget (for example, retries at most 10% of requests, or a token bucket) so retries switch off during a real outage instead of multiplying the load.
  5. Retry at one layer only, and give every attempt a timeout plus an overall deadline.

Follow-ups to expect: "What is a thundering herd?" (many clients acting at the same instant, for example retrying together after a failure). "Why not just retry immediately?" (it piles more load on a server that is already failing, and burns all attempts before a short outage ends). "How is a retry budget different from a circuit breaker?" (a budget limits retries but still sends first attempts; a circuit breaker stops sending any requests to a dependency for a while after it fails repeatedly, then lets a few test requests through to see if it has recovered).

Cheat sheet

QuestionAnswer
Why is retrying risky?During an overload, every client retries at once, multiplying the load on a struggling server.
What is exponential backoff?Doubling the wait after each failure, up to a cap.
Why add jitter?So clients that failed together do not retry together. Without it, 100 of 500 clients got through in our test; with full jitter, all 500.
Which jitter?Full jitter: random(0, min(cap, base * 2^attempt)). Simple, and it served everyone in our test.
How many attempts?Usually 3 in total (AWS SDK default: 1 request plus up to 2 retries).
What is a retry budget?A cap on retries across all requests, for example 10% or a token bucket. It cut extra load from 2.35x to 1.11x in our test.
Where should retries live?At one layer only, just above the thing that is failing.
What should not be retried?4xx errors like 400, 401, 403, 404, and non-idempotent requests without an idempotency key.
What about Retry-After?Honour it: it is seconds or an HTTP date, and the server knows best.
What else does a retried call need?A per-attempt timeout and an overall deadline.

Enjoyed this read?

Responses (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.
Keep reading

Related stories

All posts
0