Predict the output
What ceilings does this full-jitter backoff use for six attempts?
import random
def backoff_delays(
attempts: int, base: float, cap: float, rng: random.Random
) -> list[float]:
"""Full jitter: a random wait between 0 and the ceiling."""
delays = []
for attempt in range(attempts):
ceiling = min(cap, base * 2**attempt)
delays.append(rng.uniform(0, ceiling))
return delays
ceilings = [min(10.0, 0.5 * 2**a) for a in range(6)]
print("ceilings:", ceilings)
d = backoff_delays(6, 0.5, 10.0, random.Random(7))
print(
"all within ceiling:", all(0 <= x <= c for x, c in zip(d, ceilings))
)Hint 1 of 1
What does min(cap, ...) do on the sixth attempt?
Choose an answer, then open Show answer below to check it.
Illustrative; not a load test
Text version
| Strategy | 0 to <1 s | 1 to <2 s | 2 to <3 s | 3 to <4 s | 4 to <5 s | 5 to <6 s | 6 to <7 s | 7 to <8 s |
|---|---|---|---|---|---|---|---|---|
| Fixed 1 s wait | 0 | 5 | 5 | 5 | 0 | 0 | 0 | 0 |
| Exponential | 0 | 5 | 0 | 5 | 0 | 0 | 0 | 5 |
| Exponential + full jitter | 5 | 4 | 4 | 0 | 2 | 0 | 0 | 0 |
Fixed 1 s wait: C1 at 0, 1, 2, 3 s; C2 at 0, 1, 2, 3 s; C3 at 0, 1, 2, 3 s; C4 at 0, 1, 2, 3 s; C5 at 0, 1, 2, 3 s.
Exponential: C1 at 0, 1, 3, 7 s; C2 at 0, 1, 3, 7 s; C3 at 0, 1, 3, 7 s; C4 at 0, 1, 3, 7 s; C5 at 0, 1, 3, 7 s.
Exponential + full jitter: C1 at 0, 0.2, 1.3, 2.8 s; C2 at 0, 0.6, 1.9, 2.2 s; C3 at 0, 0, 1.7, 2.7 s; C4 at 0, 0.2, 2.2, 4.1 s; C5 at 0, 0.8, 1.8, 4.4 s.
Show answer
Answer: A ceilings: [0.5, 1.0, 2.0, 4.0, 8.0, 10.0] then all within ceiling: True
Correct. Doubles from 0.5 s and stops at the 10 s cap; every random delay stays under its ceiling.
Each ceiling is base × 2^attempt, cut off at the cap: 0.5, 1, 2, 4, 8, then 16 capped to 10. Full jitter draws the real wait uniformly between 0 and that ceiling, so it never goes over.
Why not the others?
- B
ceilings: [0.5, 1.0, 2.0, 4.0, 8.0, 16.0]thenall within ceiling: True. The cap limits the last one to 10 s. - C
ceilings: [0.5, 1.0, 1.5, 2.0, 2.5, 3.0]thenall within ceiling: True. That's linear backoff. - D
ceilings: [0.5, 1.0, 2.0, 4.0, 8.0, 10.0]thenall within ceiling: False. uniform(0, c) never exceeds c.