← Back to System Design, page 2

system-design-0022 · Medium mid

How do retries with exponential backoff and jitter, timeouts and circuit breakers work together to stop cascading failures?

Timeouts stop a caller waiting forever on a slow dependency. Retries recover from brief failures, but only with exponential backoff and random jitter, a retry budget, and idempotent operations, or they multiply load on a struggling service. A circuit breaker counts failures and, past a threshold, fails fast for a cool-down period before letting a few test requests through.

Full answer

How cascading failures start

The payment service slows down. The checkout service keeps waiting, so its threads fill up. Checkout now slows down, and the web tier waiting on it fills up too. Meanwhile every layer retries, so the payment service gets even more traffic. One slow dependency takes down the whole product.

Timeouts

Every network call needs a timeout based on the dependency's normal latency (for example a little above its p99), and the total budget for the user request. If the user request has a 2-second budget, an inner call cannot have a 5-second timeout. Pass a deadline down the call chain (gRPC does this natively).

Retries done safely

  • Retry only transient errors (timeouts, 503, connection reset), not 400 or 404.
  • Retry only idempotent operations, or use idempotency keys.
  • Exponential backoff: wait 100 ms, 200 ms, 400 ms, 800 ms... between attempts, with a cap.
  • Jitter: randomise the wait. Without it, a thousand clients that failed together retry together, in synchronised waves. "Full jitter" waits a random time between 0 and the current backoff.
  • Retry budget: limit retries to a small fraction of traffic (for example 10%), and retry at one layer only. If three layers each retry 3 times, one user request can become 4 x 4 x 4 = 64 calls to the bottom service.

Circuit breakers

A breaker wraps calls to one dependency and has three states:

  1. Closed: calls pass through; failures are counted over a rolling window.
  2. Open: when the failure rate passes a threshold (say 50% of the last 20 calls), calls fail immediately for a cool-down (say 30 seconds). The caller returns a fallback: cached data, a default, or a clear error.
  3. Half-open: after the cool-down, a few trial calls go through. Success closes the breaker; failure opens it again.

Failing fast frees threads and gives the dependency room to recover.

Related tools

  • Bulkheads: separate connection pools per dependency so one slow service cannot use all threads.
  • Load shedding: the overloaded service rejects excess requests early (429 or 503) instead of queueing them.
  • Fallbacks: show cached course recommendations if the recommendation service is down.

Libraries such as Resilience4j (Java) and Polly (.NET), and service meshes such as Envoy or Istio, provide these patterns.

By level

Fresher: Explain timeouts and why retrying immediately in a loop can make an outage worse, then describe backoff. Mentioning that every network call needs a timeout is expected.

Mid: Explain jitter, retry budgets, the circuit breaker state machine and bulkheads, and how timeouts relate to request deadlines. Expect the retry multiplication across layers to be shown.

Senior: Design resilience policy across a service graph: deadline propagation, retry at one layer, adaptive concurrency limits, load shedding priorities, and how to test these with fault injection. The senior answer describes how these policies are tested in practice.

Key points

  • Every remote call needs a timeout that fits the overall request deadline
  • Retry only transient errors and idempotent operations
  • Exponential backoff with jitter avoids synchronised retry storms
  • Retries at several layers multiply load; use a retry budget
  • Circuit breaker: closed, open, half-open; fail fast and use fallbacks

Common mistakes

  • Retrying without backoff or jitter
  • Retrying non-idempotent operations such as payments without keys
  • Letting every layer retry independently
  • Setting timeouts longer than the caller's own deadline

Follow-ups

  • How do you choose the failure threshold and cool-down of a breaker?
  • What fallback would you show if the pricing service is down?
  • How does deadline propagation work in gRPC?

Tips

  • Tell the cascading failure story in three steps
  • Do the retry multiplication arithmetic
  • Name the three breaker states in order

Evaluation rubric

  • Explains cascading failure mechanism
  • Correct backoff and jitter reasoning
  • Correct circuit breaker state machine
  • Mentions idempotency, budgets and fallbacks