Try again after a growing wait, with a little randomness, so retries help instead of hurt.
Retrying with backoff means that when a call fails for a short-lived reason, you try again, but you wait longer each time and add a little randomness.
In a system of many machines, calls fail all the time. A packet is lost, a server is restarting, a database is slow, or a rate limit says "too many requests". A retry is simply trying the same call again. It turns many small, temporary failures into successes that the user never sees.
But retries have a dark side. If a service is down because it is overloaded, then thousands of clients retrying at once add even more load. The service cannot recover, and the failure lasts longer. This is called a retry storm or a thundering herd.
Clients come back together, again and again.
Calmer, but still in step with each other.
Spread out. The load stays smooth.
delay_n = min(cap, base * 2^n) # n = 0 for the first retry wait = random(0, delay_n) # "full jitter" # give up when attempts > max_attempts OR total time > deadline
503 and 429 (and honour a Retry-After header if one is sent). Do not retry errors that will never change, such as 400 (bad request) or 404.| Strategy | How the wait is chosen | Good and bad |
|---|---|---|
| Immediate retry | No wait | Fine once for a tiny blip. Dangerous in a loop: it hammers the service. |
| Fixed interval | The same wait every time | Simple. But all clients stay in step, so waves of load appear. |
| Linear backoff | Wait grows by a fixed step (1 s, 2 s, 3 s...) | Gentler, but it grows slowly, so a long outage still sees many retries. |
| Exponential backoff | Wait doubles (1 s, 2 s, 4 s, 8 s...) up to a cap | Backs off fast. Still synchronised if all clients started together. |
| Exponential + jitter | A random wait up to the exponential value | Spreads clients out. The usual best choice. |
| Kind | Wait is | Notes |
|---|---|---|
| Full jitter | random(0, delay) | Spreads the most. A very short wait is possible. |
| Equal jitter | delay / 2 + random(0, delay / 2) | Keeps some minimum wait, spreads less. |
| Decorrelated jitter | random(base, previous wait x 3), capped | Each wait depends on the last one, so clients drift apart. |
The wait doubles each time (base x 2^n, capped). Clients are still in step with each other, so the waves are just further apart.
A simplified model with a simulated clock (100 ms ticks). All clients start at second 0, so the first wave is synchronised. The jitter uses a fixed seeded generator, so the same settings always give the same picture. Each wait is capped at 16 s. The numbers are illustrative, not a benchmark.
for attempt in 0..maxAttempts:
result = call()
if result.ok or not result.isRetryable:
return result
ceiling = min(cap, base * 2^attempt)
sleep(random(0, ceiling)) # full jitter
fail("out of attempts")| Term | Meaning in easy words |
|---|---|
| Retry | Trying the same call again after it failed |
| Transient error | A short-lived failure that may go away on its own |
| Backoff | Waiting between retries, usually longer each time |
| Exponential backoff | A wait that doubles after every failed try, up to a cap |
| Jitter | A random amount added to or used for the wait, to spread clients out |
| Thundering herd | Many clients acting at the same moment and overwhelming a service |
| Retry storm | A flood of retries that keeps a struggling service down |
| Retry budget | A cap on how many retries are allowed, as a share of traffic or a total time |
| Deadline | The total time after which the caller gives up, however many tries are left |
| Idempotency key | A unique ID that lets the server recognise a repeated request and not do it twice |
| Retry-After | An HTTP header in which the server says how long to wait before trying again |
| Choice | We gain | We lose |
|---|---|---|
| More attempts | More chances to succeed | More load and a longer wait before a final failure |
| Longer base wait | Calmer service, smaller waves | Slower recovery for users |
| Higher cap | Fewer calls during long outages | A single client may wait a long time |
| Full jitter | Best spreading of load | Some retries come very quickly |
| Short deadline | Fast, clear failure | Gives up before a service that would have recovered |
| Retries in every layer | Each layer is robust alone | Retry amplification (3 x 3 x 3 = 27) |