← Back to the chapter · Next detail →

Technical detail · Service Resilience: Breakers, Retries, and Timeouts

Capped exponential backoff with additive jitter

8.5.5 Capped exponential backoff with additive jitter

The calculation below doubles the base delay on each attempt, caps the exponential component, and then adds jitter from caller-provided randomness. The cap applies before jitter, so the returned delay can exceed cap_seconds. Choose the scheduling policy with the remaining deadline in view; this function does not decide retry eligibility or enforce the total budget.

def retry_delay(base_seconds, attempt, cap_seconds, jitter_fraction, random_value):
    """Return a capped exponential backoff delay with caller-provided randomness."""
    backoff = min(base_seconds * (2 ** attempt), cap_seconds)
    jitter = backoff * jitter_fraction * random_value
    return backoff + jitter

← Back to the chapter · Next detail →