What is exponential backoff?
Definition
Exponential backoff is a retry policy in which the wait before each new attempt grows by a fixed factor, usually doubling, up to a ceiling.
Doubling the wait is the part everyone remembers and the part that matters least. A policy that survives production has four pieces, and the one doing the most work is randomness.
delay = min(cap, base * 2 ** attempt) # growth, with a ceiling
delay = random.uniform(0, delay) # jitter
if attempt == max_attempts: give_up() # termination
# and if the server sent Retry-After, wait that long instead
Why the jitter matters more than the doubling
Twenty workers that fail at the same moment and follow the same schedule wake at the same moment. Their retries arrive together and can rebuild the very burst that caused the failure. Marc Brooker’s analysis on the AWS Architecture Blog compared jittered and unjittered backoff under contention and concluded that jitter should be the standard approach for remote clients. The variant he calls full jitter, used above, picks a uniformly random wait between zero and the capped delay.
We reproduced the effect in a small simulation with Python 3.15.0: 20 workers fail at time zero, base delay 1 second, ceiling 60 seconds, five retry rounds, random seed 42. The table counts the retries that land inside the busiest 100 ms window of each round.
| Retry round | No jitter | Full jitter |
|---|---|---|
| 1 | 20 | 5 |
| 2 | 20 | 3 |
| 3 | 20 | 2 |
| 4 | 20 | 3 |
| 5 | 20 | 1 |
Without jitter every retry of every round hits the target in the same instant. With it, the worst window held five. That is one seed, so read the shape rather than the exact counts.
What Python’s requests actually does
Out of the box, nothing. In requests 2.32.3 the adapter’s DEFAULT_RETRIES is 0, so a failed request fails once and returns. Retries come from urllib3’s Retry class, mounted on a session. We read urllib3 2.3.0’s source and ran it to see the real schedule:
- With
backoff_factor=0.5the waits were 0, 1, 2, 4, 8, 16, 32 and 64 seconds. The first retry is immediate. After that the wait is the factor times 2 raised to the number of consecutive failures minus one. - The ceiling is
DEFAULT_BACKOFF_MAX, 120 seconds. - Jitter is off unless you set
backoff_jitter, and it is added on top of the computed wait rather than replacing it. - On 413, 429 and 503 responses that carry Retry-After, the server’s value replaces the schedule. Against a local server answering 429 with
Retry-After: 3, urllib3 waited 3.01 and 3.00 seconds where its own schedule said 0 and 1.
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
retry = Retry(
total=5,
backoff_factor=0.5, # waits 0, 1, 2, 4, 8 s between attempts
backoff_jitter=1.0, # adds 0 to 1 s at random to each wait
status_forcelist=[502, 503, 504],
allowed_methods=["GET", "HEAD"],
) # 413, 429 and 503 with Retry-After obey the server
session = requests.Session()
session.mount("http://", HTTPAdapter(max_retries=retry))
session.mount("https://", HTTPAdapter(max_retries=retry))
A hand-written loop for httpx, with the same two rules, is in retries that do not make things worse. The version tuned for 429 responses through a proxy is in backoff that does not resynchronise.
Where the idea comes from
TCP did it first. RFC 6298 tells a host to set the retransmission timeout to twice its previous value after each timeout, in its own words to “back off the timer”, and allows a maximum provided it is at least 60 seconds. Every HTTP retry policy runs on top of a transport that is already backing off underneath it.
When backoff is the wrong tool
Backoff answers transient failure: a reset connection, a timeout, a 503 during a deploy. It does nothing for a 403, which is a refusal and needs something to change, or for a CAPTCHA page, which is a classification and gets worse with persistence. It also cannot fix a steady request rate that the target will not accept. Above that line, backoff produces a slow oscillation around the limit and a poor success rate; the cure is a lower rate set in advance, covered under rate limiting. An agent with a person waiting on the answer needs a tighter bound still, as argued in bounded retries, because someone is waiting.