Bookmarks

Retry with exponential backoff

A strategy for retrying failed requests: between attempts the client waits for a delay that grows from attempt to attempt, usually doubling, up to a set ceiling.

Also: exponential delay, exponential backoff strategy, exponential backoff, retry with backoff

checked 8 Nov

All terms

A brief failure of a dependency — a timeout, a dropped connection, a 503 response — often goes away on its own: a retry a second later reaches a service that has already recovered. But a retry without a delay adds load to a dependency that is already overloaded — this is how a retry storm starts. A growing delay gives the failing service room to breathe, and a cap on attempts keeps the client from retrying forever.

How the delay grows

The delay is computed from the attempt number: the base interval is multiplied by a base, most often 2, which produces a geometric progression. Growth is limited by a ceiling, otherwise the tenth attempt would have to wait for minutes.

AttemptFormulaExample: a base of 100 ms
1100 ms × 2⁰100 ms
2100 ms × 2¹200 ms
3100 ms × 2²400 ms
4100 ms × 2³800 ms
5100 ms × 2⁴1.6 s
6100 ms × 2⁵ → ceiling of 2 s2 s

Jitter

Without a random addition — jitter — clients that have come through the same failure compute identical delays and retry in synchronised waves: each wave hits the dependency again, and it cannot recover. Jitter spreads the attempts out in time; at Amazon it is added not only to retries but also to timers and periodic jobs. The variants: full jitter — the delay is uniformly random from zero to the computed value; equal jitter — half of the delay is fixed, the other half is random; decorrelated jitter — the maximum of the next delay grows from the last random value.

What else is limited

  • the number of attempts — usually 3–5, after which the error is handed back to the calling code; in gRPC a policy of more than five attempts is capped at five anyway;
  • which errors to retry — timeouts, dropped connections and the status codes 429 and 503; a 429 response may carry a Retry-After header saying how long to wait — it takes precedence over the client’s own calculation;
  • the retry layer — one only: AWS cites an example of a stack of five calls with three attempts in each — the multiplication of attempts raises the load on the database 243-fold;
  • retry safety — the operation must be idempotent or carry an idempotency key, otherwise a retry will create a second payment or a second order.

Example

yamlA gRPC retry policy: five attempts, a delay from 100 ms to 2 s
retryPolicy:  maxAttempts: 5  initialBackoff: 0.1s  maxBackoff: 2s  backoffMultiplier: 2.0  retryableStatusCodes: [UNAVAILABLE]

Sources

the term is written from these pages

Verified 8 Nov

Not to be confused with

what it is mixed up with and how it differs

  • circuit breaker

    A retry keeps calling the failing service with delays in between, while a circuit breaker, after a run of failures, stops calling it altogether for a while.

  • idempotency

    The delay answers when to repeat a request; idempotency — whether it can be repeated at all without the risk of doubling the effect.

In depth in the references

where the topic is covered in detail