Skip to content

Resilience patterns · 3 of 9

Step 1 · The pattern

A healthy service

Clients call the payment service. It has room for ten requests at a time and normal traffic keeps it about 70% busy. Every request succeeds.

  • request
  • success

In short

Backoff + jitter: how it works and how it breaks

Retries turn a failed request into a successful one, which is why every client library has them. They also multiply load at the worst possible time. When a service fails, every caller retries, and each failed retry is retried again. A service that could handle normal traffic now receives several times as much, right as it tries to come back. It rejects most of it, which causes more retries, and the outage outlives its cause. Two changes break the loop. Exponential backoff makes each client wait longer after every failure, so pressure falls instead of rising. Jitter adds randomness to each wait, so clients that failed together do not return together. Add a cap on attempts, or a retry budget, so the extra load stays bounded. Automatic retries are only safe when the operation is idempotent.

In Spring Boot

Retry with exponential backoff and jitter in Resilience4j

application.yml
resilience4j.retry:
  instances:
    inventory:
      maxAttempts: 4              # the first call counts as one
      waitDuration: 200ms
      enableExponentialBackoff: true
      exponentialBackoffMultiplier: 2
      enableRandomizedWait: true  # this is the jitter
      randomizedWaitFactor: 0.5
      retryExceptions:
        - java.io.IOException

Waits grow from 200 ms by a factor of two, and each one is moved by a random amount of up to half its length, so callers that failed together do not retry together. Put @Retry(name = "inventory") on the method that makes the call.

Gotcha: Backoff alone is not jitter: you need both enable flags. With only enableExponentialBackoff every client still retries at the same instants. Retry only calls that are safe to repeat, and remember that Retry wraps the circuit breaker, so each attempt is counted by the breaker.

How this comes up in interviews

"A service was down for two seconds, yet the outage lasted far longer. Its clients retry failed calls. What happened, and how do you fix the clients?"

Then they ask

  1. Every client backs off exponentially with exactly the same delays. What does the service see?
  2. A cap on attempts is in place, yet load still multiplies when everything is failing. What bounds it?
  3. Which failures are safe to retry automatically, and what about a timeout on a write?

A strong answer covers

  • Immediate retries multiply load as the service returns. It rejects most of it, which causes more retries, so the outage outlives its cause.
  • Exponential backoff makes each client wait longer after every failure, so pressure falls instead of rising.
  • Jitter adds randomness to each wait, so clients that failed together do not return in synchronised waves.
  • A cap on attempts, or a retry budget, keeps the extra load bounded.
  • Automatic retries are only safe when the operation is idempotent.

Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.

On one page: the track cheat sheet.

Last updated: Research paper

Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.