← All Exercises
Retry Delays with Full Jitter
intermediatejavascript
Background
Full jitter decorrelates concurrent clients so retries spread uniformly across the backoff range instead of synchronizing into thundering herds. AWS architects popularized the formula.
Problem
Compute retry delays using full jitter: for retry attempt i (starting at 1), the exponential cap is min(maxMs, baseMs * factor^i), and the delay is the cap multiplied by random seed i-1, rounded to the nearest integer. Output the delay for every provided seed.
Input
A JSON object {"baseMs": number, "factor": number, "maxMs": number, "jitterSeeds": number[]} of seeds in [0, 1).Output
A JSON object {"delays": number[]} with one integer delay per seed.Sample tests
Sample 1
Input: {"baseMs":100,"factor":2,"maxMs":800,"jitterSeeds":[0.1,0.55,0.99]}Expected: {"delays":[20,220,792]}Sample 2
Input: {"baseMs":50,"factor":2,"maxMs":100,"jitterSeeds":[0,0.5,1]}Expected: {"delays":[0,50,100]}Your solution
Learning objective
Translate the full-jitter backoff formula into code and reason about its distribution.