Try
↑ ↓ move↵ openesc close
In this lesson · topic 2 of 7
  1. 1. When a retry makes it worse
  2. 2. Backoff, jitter, budgets and breakers
  3. 3. Break a dependency and compare six retry policies
  4. 4. Jitter spreads retries, only budgets and breakers cap them
  5. 5. Hedging the slow tail
  6. 6. Deadlines down the chain, keys across the retry
  7. 7. Sizing the retry safety net

Topic 2

Backoff, jitter, budgets and breakers

5 min read

Start with a timeout

Everything below depends on the client giving up. A call with no timeout can hang for as long as the dependency does, and it holds a thread, a connection and memory the whole time. Pick the timeout from what the user is willing to wait, and from the dependency’s normal latency at a high percentile. Too short and you retry work that was about to finish. Too long and a slow dependency ties up its callers. When a request passes through several services, send the remaining time along with it, so that a service deeper down does not keep working after the caller has stopped waiting.

Retry only what is safe

A retry sends the request again, so the operation must be safe to repeat. Reads are. A write that charges a card is not, unless it carries an idempotency key that lets the server recognise the repeat. Retry on errors that might clear up: a timeout, a connection reset, a 503. Do not retry on errors that will not, such as a bad request.

The tools

Immediate retry. Try again on the next tick. It is what a naive loop does. It adds the most load when the dependency has the least spare capacity.

Exponential backoff. Wait longer after each failure, typically doubling up to a cap. The dependency gets room to recover, and the load from a long-failing client falls off.

Full jitter. Pick each wait at random between zero and the backoff ceiling. Plain backoff has a problem when many clients fail at the same moment. They all wait the same time and come back in step, wave after wave. Randomising each wait spreads the retries over the whole window.

Retry budget. Allow retries only up to a fraction of recent requests. In the lab every new request earns a tenth of a token, and a retry costs a whole one. When the dependency fails, the budget runs out after a few retries and the rest fail at once. The extra load can never exceed that fraction, whatever the failure rate. The Google SRE book describes limiting retries per request and per process, and the gRPC retry design has a throttling rule of this kind.

Circuit breaker. A guard that watches recent outcomes. It is a small state machine with three states.

A circuit breaker through one incident

Step 1 / 5
closedopenhalf-openhalf of recent attempts failafter 20 ticks3 probes passa probe failsrecent attempts
state
closed
recent failures
0 of 20
  1. Closed

    Everything is healthy. Requests flow to the dependency and the breaker only watches how the recent ones went.

  • Closed. Requests go through. The breaker counts failures.
  • Open. Too many recent attempts failed. Requests fail immediately and are not sent, for a cool-down period.
  • Half-open. After the cool-down, a few probes are let through. If they succeed, the breaker closes. If one fails, it opens again.

In the lab, one breaker stands for all the clients. It opens when half of the last 20 attempts failed, waits 20 ticks, then sends 3 probes. In production the thresholds and the cool-down are tuned per dependency.

What to watch

Two numbers tell you whether the policy is safe. Attempts per request says how much load retries add. Dependency load says whether the sum of new work and retries is above what the dependency can serve. The lab plots both.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms