Video in progress

Strong Junior 🧩 Microservices

Why do you need exponential backoff and jitter in retries?

Exponential backoff increases the wait after each attempt (100 ms, 200, 400...), giving a struggling service time to breathe. Jitter adds a random amount to the wait, so hundreds of clients don't retry together at the same instant.

📖 Answer

Imagine retries with no backoff: inventory-service froze for 2 seconds. 500 requests got an error and retried immediately, then again immediately. While the service is recovering, it gets 3 times the usual load and falls over again.

Exponential backoff alone isn't enough either: all the clients got the error at the same time, so they all retry after exactly 100 ms, then after exactly 200 ms. The load arrives in waves (the "thundering herd").

Jitter spreads those waves out:

resilience4j:
  retry:
    instances:
      inventory:
        max-attempts: 3
        wait-duration: 200ms
        enable-exponential-backoff: true
        exponential-backoff-multiplier: 2
        enable-randomized-wait: true
        randomized-wait-factor: 0.5

Now the wait is ~200 ms ± 50%, then ~400 ms ± 50%, and the attempts are spread out over time.

One more limit: keep the total wait acceptable for the user. If the gateway gives up after 5 seconds, a 10-second retry series inside the service only burns resources.