Part 05 / Topic 3 of 7
Rate limits and retries
A 429 is not an error in the moral sense — it is the API telling you its price. Respect it: wait for Retry-After if given, otherwise back off exponentially (1 s, 2 s, 4 s…). Exponential backoff gives a struggling service room to recover; add jitter (a random fraction of the wait) so a fleet of clients does not retry in lockstep and re-create the stampede.
wait = min(cap, base * 2 ** attempt) * random.uniform(0.5, 1.5) # backoff with jitter
Also set a total budget (give up after N attempts or T seconds) — a client that retries forever turns one outage into two.
🧪 Quick quiz
- What is exponential backoff?
Show the answer
Waiting longer after each failed attempt — e.g. 1 s, 2 s, 4 s. It gives the struggling service room to recover; add random jitter so many clients do not retry at the same moment.
Done here? The practice set for Part 5 — 4 exercises with solutions — is on the part page.