Want the details?
Why retries can hurt
Networks and servers fail for a moment all the time, so clients retry: they try the same request again. That is good. But when a server fails for everyone at once, every client starts retrying at the same moment. If they all use the same waiting time, they stay in step, and their retries arrive together, like a crowd pushing through one door. This is called a thundering herd or a retry storm. The server that just came back falls over again under the crowd.
Two ideas fix it. Backoff: wait longer after each failure, so the total load goes down. Jitter: make each wait partly random, so the clients get out of step. You need both.
How to read the bench
| Part on the bench | What it means in a real system |
|---|---|
| 30 lamps at the left | 30 users of an app, each with a long-lived connection (a chat app, a game, a phone app with live updates). Lit: connected. |
| Ball on the lane | One attempt to connect. |
| Dial on the server | Attempts in the last second. The marked part from 18 up is where the server falls over. |
| Tray | Attempts the server turned away, because it was down or already full for this second. |
| Cross on the server | The server is down: restarting, or fallen over. |
| Bars under the picture | Attempts in each of the last 20 seconds. A striped bar reached the crash line. |
The numbers
- 30 users. The server accepts up to 10 new connections a second.
- 18 or more attempts within one second knock it over for 2 seconds, and it drops everyone who was connected.
- The planned restart takes 3 seconds.
- Doubling: 1, 2, 4, 8, then 16 seconds at most.
- Doubling + random ("full jitter"): a random wait between 0 and the doubling wait.
- Over one minute: 1 second fixed, about 1,140 attempts and 28 crashes; random up to 1 s, about 1,700 attempts; doubling, about 410 attempts and 13 crashes. None of them gets everyone back. Doubling + random: 80 to 160 attempts, at most 2 crashes, and everyone back after 7 to 25 seconds (we checked 40 different random seeds).
The page uses a seeded random generator, so the same lesson gives the same run each time, and the test checks every number above.
In real systems
- Cloud SDKs (AWS, Google Cloud, Azure) retry with exponential backoff and jitter by default.
- Retry-After. A server can answer
429or503with aRetry-Afterheader that tells the client how long to wait. This is backpressure (the previous lab) sent over the network. - Limit retries. Give up after a few attempts, or use a retry budget: retries may be at most, say, 10% of all requests. Otherwise every layer retries and the load multiplies.
- Retry only what is safe. Reading is safe to repeat. A payment is not, unless it carries an idempotency key (see the lesson on delivery guarantees).
- Add a circuit breaker (lab 7) so a client stops trying a service that is clearly down.
Words to know
- Retry
- Sending the same request again after a failure.
- Exponential backoff
- Doubling the wait after each failure, up to a limit.
- Jitter
- A random part added to the wait, so clients do not stay in step.
- Thundering herd
- Many clients waking up and hitting the same thing at the same moment.
- Retry budget
- A limit on how many retries a client may send, compared to its normal requests.