Book a 30-min callBook a call

Retries, exponential backoff, jitter and circuit breakers

When to retry a failed call, how exponential backoff and jitter work, retry budgets, deadlines, Retry-After, circuit breakers, bulkheads and load shedding.

A client box sending calls to a service box through a switch with three colored positions, with retry marks below spaced farther and farther apart among small scattered dots.
Written by
BYD Tech
Published
Topic
Deep dives
Reading time
19 min read

Questions people ask

Which errors should a client retry?

Transient ones: connection failures before the request was sent, timeouts, 502, 503 and 504, and 429 after the Retry-After delay. Do not retry 400, 401, 403, 404 or 422, and do not retry a non-idempotent request whose outcome is unknown unless it carries an idempotency key. For database transactions, retry serialization failures and deadlocks by rerunning the whole transaction.

What is the difference between full jitter and decorrelated jitter?

Full jitter waits a random time between zero and the capped exponential backoff for that attempt number. Decorrelated jitter ignores the attempt number and waits a random time between the base delay and three times the previous wait, capped. In the AWS Architecture Blog simulation, full jitter did slightly less work and decorrelated jitter finished slightly sooner.

How many retries are too many?

Fewer than most defaults. Three or four attempts per request at one layer is common, but the stronger limits are a deadline for the whole request and a retry budget that keeps retries to a small share of traffic, such as Envoy's default of 20% of active requests. Retrying at several layers multiplies attempts, so pick one.

Does a circuit breaker replace retries?

No, they do different jobs. Retries handle brief, scattered failures; a circuit breaker handles a dependency that is down, by failing fast and sending occasional trial calls. Use both, with retries going through the breaker and stopping as soon as it reports that it is open.

Should I always honor Retry-After?

Yes, as a minimum wait, with some jitter added so clients do not return together. If the delay does not fit inside the request's remaining deadline, fail immediately instead of sleeping. Clamp unreasonably large values, and treat an HTTP date in the past as no wait.

Building something like this?