Timeouts, Retries, Backoff and Jitter
Overview
Resilience is a system's ability to keep working, or recover quickly, when parts of it fail. The first two tools are a timeout (stop waiting after a fixed time) and a retry (try again when a failure is probably temporary). Used carelessly they cause outages; used well they hide small failures from users.
Detailed Notes
What is a timeout, and what is a retry
A timeout is a limit on how long you will wait for a response. A retry is automatically repeating a failed operation. Together with exponential backoff (waiting longer after each failure) and jitter (randomness added to that wait), they are the basic building blocks of resilient code.
The problem it solves
Every network call can be slow, lost or answered with an error. Imagine a product page calling a recommendations service that normally answers in 50 ms but is overloaded and takes 60 seconds.
- No timeout: every page request waits a minute, threads pile up until all are busy, and the whole site stops responding.
- With a 300 ms timeout: the page gives up quickly, shows the product without recommendations and stays fast.
If the service recovers but 10,000 clients all retry at the same instant, the flood knocks it over again. That is a retry storm.
How it works
Timeouts. A waiting caller holds threads, memory and connections; a limit stops one slow dependency from draining them. A connection timeout limits the time to connect, a read timeout limits the wait for the response, and an overall deadline caps the whole operation including retries. Pick values from measured latency (a little above the dependency's p99), never "infinite".
Transient vs permanent failures. A transient failure goes away by itself (a network blip, a restarting server, HTTP 429 "too many requests", HTTP 503 "temporarily unavailable"), so retrying helps. A permanent failure will not change (400 invalid input, 401 wrong password, 404 missing item), so retrying only wastes effort.
Exponential backoff. Wait 100 ms, then 200, then 400 (doubling), giving a struggling service time to recover. Jitter adds randomness: without it, thousands of clients that failed together retry together in waves; with "full jitter" each waits a random time between 0 and the backoff limit, spreading the load.
Retry amplification. If A retries 3 times against B, and B retries 3 times against C, one user request becomes 9 calls to C, exactly when it is weakest. Retry at one layer only, use a retry budget (retries capped at, say, 10 percent of normal traffic), and pass a deadline down the chain so deeper services drop work the caller has abandoned.
Only retry operations that are safe to repeat (a later lesson explains how).
A simple example
You phone a friend and the line is busy. You wait, try again, then wait longer (backoff). If ten people all call at exactly 9:00:00 the line jams again, so each picks a slightly different moment (jitter).
System design example
A checkout service calls a payment gateway with a 600 ms timeout. On a timeout, 429 or 503 it retries at most twice, waiting a random 0-100 ms, then 0-200 ms. It never retries a 400, and the whole checkout has a 2-second deadline.
Summary
- Every remote call needs a timeout.
- Retry only transient failures of operations that are safe to repeat.
- Backoff gives recovery time; jitter prevents synchronised retry storms.
- Retry at one layer and pass a deadline down the chain.
Architecture Diagram
Each failed attempt waits longer, with random jitter, before the next try.
- 1The client calls the service with a timeout.
- 2On a transient failure it waits a random time within a growing limit, then retries.
- 3If still failing at the limit or deadline, it fails fast or uses a fallback.
Common Interview Questions
Finished this lesson?
0 of 91 lessons done · 0% of the course

