Why retries collide#
A dependency goes down for thirty seconds: a payment API, a Redis primary failing over, a Postgres replica restarting. Every job that touched it during that time fails. If each one retries after the same delay, they all come back together, and the service that is trying to recover gets the whole backlog in one burst. Backoff spaces out each client’s attempts over time. Jitter spaces out different clients from each other. You need both, and the second one is the one people forget.
This tool simulates that moment. A number of clients, which in a Rails app are usually jobs, fail at the same instant and retry on a schedule. The first chart shows the delay before each retry; the second shows when the retries actually arrive. The verdict counts the retries that land in the busiest window, and compares that with the same settings without randomness.
How it works#
The jitter strategies follow Marc Brooker’s article Exponential Backoff And Jitter on the AWS Architecture Blog (March 2015). Its formulas, with attempt starting at 0 for the first retry:
- Exponential:
sleep = min(cap, base * 2 ** attempt) - Full jitter:
sleep = random_between(0, min(cap, base * 2 ** attempt)) - Equal jitter:
temp = min(cap, base * 2 ** attempt), thensleep = temp / 2 + random_between(0, temp / 2) - Decorrelated jitter:
sleep = min(cap, random_between(base, sleep * 3))
The article does not say where the decorrelated sleep starts. Its companion simulator, published with the post, starts it at base, and so does this tool. The multiplier is an input so you can try other growth rates; at 2 the formulas are exactly the article’s. Constant and linear backoff are there for contrast.
Two Rails curves are included for comparison, with their verified formulas. Sidekiq 8.x’s default waits count**4 + 15 + rand(10 * (count + 1)) seconds, with count starting at 0. Active Job’s wait: :polynomially_longer waits executions**4 + 2 plus up to 15% of executions**4 as jitter, with executions starting at 1. These ignore the base, cap and multiplier, which the form hides when you pick them.
Randomness comes from a seeded generator (mulberry32), not Math.random, so a seed always replays the same run. For each strategy the tool also computes the theoretical minimum, expected and maximum delay per retry, and the tests check that every simulated delay stays inside those bounds. Decorrelated jitter has no simple expected value once the cap applies, so its expected column shows the simulated mean. Nothing you enter leaves the page.
Worked example#
Take the defaults: 100 jobs fail together, retry 8 times, base 5 seconds, cap 300 seconds, multiplier 2, seed 42, and a 1 second window for the peak.
- Exponential, no jitter: the delays are 5, 10, 20, 40, 80, 160, 300 and 300 seconds. All 100 jobs retry at 5 s, 15 s, 35 s and so on, so each wave puts 100 retries into the same second. The last retry fires at 915 s. Constant and linear backoff behave the same way: the spacing changes, the collisions do not.
- Full jitter: the busiest second holds 38 retries out of 800, against 100 without the randomness. The expected delays are half the exponential ones, 2.5 s up to 150 s, so the whole schedule is shorter: on average a job’s last retry fires at 454 s.
- Equal jitter: the busiest second holds 54. Each delay is at least half the exponential value, so retries never come back almost at once, but they stay closer together than with full jitter.
- Decorrelated jitter: 20 in the busiest second, the lowest of the three, with a mean last retry at 523 s.
- Sidekiq 8.x default: 19 in the busiest second. Its jitter adds 0 to 9 seconds even at the first retry, and its delays grow with the fourth power, so jobs separate quickly. The schedule is far longer: 8 retries take about 83 minutes on average.
- Active Job polynomially_longer: Bunched. All 100 first retries land between 3.0 and 3.15 seconds, because 15% of
1**4is 0.15 seconds. The later retries spread out, but the first wave arrives together.
Now set the base to 1 second and pick full jitter again. The busiest second rises above 100, more than without jitter, because many first and second retries choose a delay close to zero. The tool calls this Bunched. A small base with full jitter trades a retry storm at fixed times for a burst right at the start.
The Rails angle#
Sidekiq lets you replace its delay with a sidekiq_retry_in block that receives the retry count. The generated code puts the chosen formula there, with two adjustments. Sidekiq converts the value to whole seconds and treats 0 as “use the default formula”, so the delay is rounded up to at least 1 second. Sidekiq also adds its own jitter on top of whatever the block returns, so your delays are slightly longer than the chart shows.
Active Job’s retry_on accepts a proc for wait: that receives the execution count, which is 1 on the first failure, so the generated code uses executions - 1 as the attempt. Active Job adds no jitter to a proc’s result, so the randomness in the proc is all there is. Remember that attempts: counts the first execution, so 8 retries means attempts: 9.
Decorrelated jitter needs the previous delay, and neither hook passes it in. The generated code falls back to full jitter for it and says so.
Jitter decides when retries arrive. Whether a job should retry at all is a separate decision: a validation error will fail the same way every time. Sidekiq retry strategy: transient vs permanent failures covers that split, and why a Sidekiq job can run twice explains why every retried job must be safe to run again. To see the exact clock time of each Sidekiq retry, use the Sidekiq retry calculator.
Limitations and assumptions#
- Every attempt fails. The simulation shows the full schedule while the dependency is down. Real retries stop when one succeeds.
- No execution time. A retry arrives at the instant its delay ends; the time the job takes to fail is not added. Add it to the base if it matters.
- Scheduler resolution. Sidekiq and Active Job adapters run scheduled jobs when a poller picks them up, not at the exact second, which adds its own small spread.
- One failure moment. All clients fail at time zero. Failures spread over a minute already have some separation.
- Versions. The Sidekiq curve is the 8.x jitter. Sidekiq 7.x uses
rand(10) * (count + 1)instead, which moves in steps ofcount + 1up to nine times that. The Active Job curve assumesretry_jitter0.15, the default withload_defaults6.1 or later.
Frequently asked questions
What is the difference between full, equal and decorrelated jitter?
All three start from capped exponential backoff, min(cap, base × 2^attempt). Full jitter picks a random delay between zero and that value. Equal jitter keeps half of it and randomizes the other half, so it never retries almost at once. Decorrelated jitter picks a random delay between the base and three times the previous delay, then caps it, so each client wanders on its own path.
Which jitter strategy should I use?
The AWS article that defined these three found that plain exponential backoff did the most work and took the longest, that equal jitter did slightly more work than full jitter and took much longer, and that the choice between full and decorrelated jitter was less clear. Full jitter is the simplest to write as a stateless function, which is what Sidekiq and Active Job give you.
Why does full jitter sometimes put more retries in the first second than no jitter at all?
Because it can pick a delay close to zero. With a 1 second base, the first and second retries of every client fall somewhere in the first few seconds, so they pile up there. A larger base, or equal jitter, keeps the early retries apart. The tool reports this as Bunched rather than hiding it.
Does Sidekiq already add jitter to retries?
Yes. Sidekiq 8.x adds rand(10 × (count + 1)) seconds to every retry delay, including the value your sidekiq_retry_in block returns. Sidekiq 7.x adds rand(10) × (count + 1). Both are small next to the count⁴ + 15 base at later retries, but they do spread the early ones by several seconds.
Is Active Job retry_on jitter enough to prevent a retry storm?
Not at the first retries. With wait: :polynomially_longer and the default retry_jitter of 0.15, the first retry waits 3 seconds plus up to 0.15 seconds, so a burst of failures retries within the same fraction of a second. The spread grows with the fourth power of the execution count, so later retries do separate.
Why is a seed needed? Real retries are random.
The seed makes the simulation repeatable: the same inputs and seed always produce the same picture, so a share link shows exactly what you saw and the tests can check fixed values. Press New seed to draw a different run; the shape should stay the same, only the details move.
Does the tool model the service recovering or jobs succeeding?
No. Every client fails at time zero and every retry fails, so you see the whole schedule. Real retries stop when a call succeeds, which thins out the later waves. The tool answers a narrower question: how tightly do the retries arrive while the dependency is still down?