When retries make it worse
9,000 req/s on five servers. One server crashes, and the four left are a little short. That should cost you about one request in ten. Instead most of the site goes down, because every failed request is tried again, and again.
Play this levelPart of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
Retrying a failed request feels safe. But a system fails because it's short of capacity, and each retry is one more request. The load goes up exactly when the system can least take it.
Run the crash test below and look at the numbers: users send 9,000 req/s, but far more than that hits the servers. This is a retry storm. It can keep a system down long after the first fault is fixed.
The fix lives in the client. Exponential backoff waits longer after each failure: 1 second, 2, 4. Jitter makes each client wait a random amount, so they don't all return in the same instant. A retry budget lets only a small share of requests retry at all.
Click **Users** and tick **Back off on retries**. And only retry what's safe to repeat: a read is, a payment isn't, unless it carries an idempotency key.
What you have to achieve
9,000 requests a second at the busiest hour, 3% of them writes.
- No broken or illegal connections
- No component is overloaded
- After any one machine crashes and failover ends, under 15% of requests fail
- Fewer than 0.1% of requests fail
- Machines cost at most $1,350 / month
What you learn
With backoff, losing a server costs about what it should: the requests the missing machine would have answered. In a real system, work that keeps failing goes to a dead letter queue, where a person can look at it, instead of being retried for ever.
Check yourself
10,000 phones lose their connection and all retry exactly 1 second later. What does jitter change?
- They retry sooner
- Each waits a slightly different random time, so they don't all arrive together
- They stop retrying
Show the answer
Each waits a slightly different random time, so they don't all arrive together. Without jitter the retries arrive as one wave, again and again. A random wait spreads the same retries over time.
A job in a queue has failed 5 times in a row. What should happen to it?
- Retry it for ever
- Delete it silently
- Move it to a dead letter queue and alert someone
Show the answer
Move it to a dead letter queue and alert someone. It will probably fail a sixth time. Parking it keeps the queue moving and keeps the job for someone to inspect.