Skip to content

Why retries need jitter

100 clients call the same host at the same moment. The host is down for the first second. After that it can serve 40 requests per second.

Every failed client retries up to 5 times, with exponential backoff. On the left, all clients wait the same time. On the right, they use Vereda's jitter. Press Play: the page slows down at key moments to explain.

t = 0.0 s

First attemptRetryServedFailed: host downFailed: over capacity

Backoff, no jitter

retry: { maxRetries: 5, backoff: { baseDelayMs: 200, jitter: false } }
0peak load after outage, attempts/s
0attempts sent
0clients served
…all clients finished at

Backoff + jitter

retry: { maxRetries: 5, backoff: { baseDelayMs: 200, jitter: true } }
0peak load after outage, attempts/s
0attempts sent
0clients served
…all clients finished at

Attempts reaching the host (per second)

Each point counts the attempts in 100 ms and shows them as a rate. The dashed line is what the host can serve. Without jitter, every wave is a tall spike.

Clients served so far

Jitter gives the host a steady stream it can serve. The spikes on the left serve only a few clients each, because the host takes only its capacity from each spike.

What jitter gives you

  1. Retries spread out. Without jitter, every client waits 200 ms, then 400 ms, then 800 ms. They all started together, so they all come back together. With jitter, each client picks its own random delay.
  2. Lower peaks. The host still sees too many requests at first, but far fewer than in one big wave. The peak falls with every round, and more requests get an answer.
  3. The spread grows. Each retry doubles the window the delay is picked from. The later the retry, the wider the spread.

What it costs

  • Some clients retry very soon. The delay can be close to 0 ms, and on average it is half of the plain backoff delay.
  • Finish times are less predictable. One client with bad luck can wait longer than the rest.
  • The host still has the same capacity. Jitter only gives its requests a better order. If the outage is longer than all the retries, every client still gives up.

Things to try:

  • Set baseDelayMs to 50. The retries come back so fast that 4 of the 5 land while the host is still down. Even with jitter, only 17 of 100 clients are served, against 90 at 200 ms.
  • Raise maxRetries, and watch the no-jitter lane send the same wave again and again.
  • Lower maxDelayMs to 1 s. Once the delay reaches the cap, the no-jitter waves come exactly 1 s apart, and jitter serves 62 of 100 clients instead of 90.

In Vereda

HttpClient.create({ timeout: { attemptMs: 5_000 }, retry: { maxRetries: 5, backoff: { baseDelayMs: 200, maxDelayMs: 30_000, jitter: true, // the default }, }, })

src/core/backoff.ts builds the delay for retry number attempt, counted from 0. It takes baseDelayMs * 2 ** attempt and caps it at maxDelayMs.

With jitter: true, the default, it returns Math.random() * capped. This is full jitter: a random value from 0 to the capped delay.

A Retry-After header changes this. When a retryable status such as 429 or 503 comes with that header, resolveRetryDelay in src/queue/retry.ts uses the header value, capped at maxDelayMs, and adds no jitter.

So if the host tells every client the same number of seconds, they all come back together. This page shows plain failures with no header.

A backoff function you write yourself is used as it is, with no jitter added.

Simplified model: the host answers each request at once, and it serves up to its capacity in every 100 ms step.

Each client here is its own HttpClient, so no retry waits for anything but its delay. If one client sent all these requests, a retry would also wait for a free slot in its partition's bulkhead.

A test (test/demos/backoff-jitter.parity.test.ts) runs this page's model against the real HttpClient, so the page has to change when the library does.