Containing failure
Everything fails — machines, networks, dependencies, disks. That's not the design question. The design question is: does one failure stay one failure, or does it become ten thousand? The patterns in this lesson are firebreaks — mechanisms that stop a local fault from cascading into a total outage. And the first villain is the humble missing timeout.
Timeouts: the mandatory seatbelt
Every network call needs a timeout. Follow the chain of what happens without one: a dependency hangs (not fails — hangs, which is worse, because failure returns and hanging doesn't). Your service's calling thread waits. Forever. So does the connection it holds. More requests arrive, more threads wait, and shortly your thread and connection pools are fully exhausted waiting on someone else's problem — and now your service is down, taken out not by its own bug but by its patience. Set timeouts from the dependency's measured p99 (from Lesson 9.01's dashboards), not from optimism. A timeout slightly too tight fails a few slow requests; no timeout at all fails everything, eventually.
Retries: the most dangerous safety mechanism
A retry assumes the failure was transient. Now zoom out and watch the assumption at fleet scale: a service degrades under load. Every one of its thousand clients retries three times. Offered load triples at the exact moment the service is weakest — the rescue party trampling the patient. That's a retry storm, and it turns wobbles into outages. The discipline:
- Exponential backoff with full jitter. Wait 1s, 2s, 4s — but randomised across the whole interval. Without jitter, every client that failed together retries together, in synchronised waves: a self-inflicted thundering herd, arriving on schedule.
- Retry only idempotent operations — or ones carrying an idempotency key (Tier 1's lesson, load-bearing again). Retrying a non-idempotent POST is how double charges happen.
- Retry at ONE layer. The silent multiplier: three layers each innocently retrying 3× compounds to 27 requests for one user action. Pick the layer that owns the decision (usually nearest the user); everyone else fails fast and passes the error up.
- Retry budgets. Cap retries at ~10% of total traffic. Budget exceeded means the dependency is genuinely down — stop resuscitating it and fail fast.
Circuit breakers: stop calling the dead
When a dependency is truly down, even sending requests costs you — threads, connections, timeout-lengths of waiting. A circuit breaker watches the failure rate, and past a threshold it opens: calls fail instantly, no network attempt. Periodically it goes half-open, letting a few probes through — success closes it, failure re-opens it. Two gifts: your service stops bleeding resources into a corpse, and — subtler — the struggling dependency gets breathing room to actually recover, instead of being hammered mid-resuscitation by loyal clients.
The essential companion: a fallback — a plan for the open state. Serve the cached copy. Show generic recommendations instead of personalised ones. Degrade the feature, not the page. An open breaker with no fallback is just a faster path to the same error screen.
Bulkheads and load shedding: partition and triage
Bulkheads — named for the walls that keep one flooded ship compartment from sinking the vessel — partition resources per dependency: separate connection pools, separate thread pools. When the payments API hangs, it exhausts its own pool of 20 connections and not one more; search and browse never feel it. Without bulkheads, one sick dependency drains the shared pool and everything fails together, mysteriously.
Load shedding is the last line: more work is arriving than exists capacity to do, and serving everyone badly is choosing to fail everyone. Shed: reject low-priority traffic (crawlers, prefetches, analytics) fast and cheap, and spend the capacity that remains serving real users properly. A degraded system that triages beats an egalitarian one that collapses.
Shipping retries with no jitter and no budget, then discovering your clients have formed a synchronised battering ram. The signature in the graphs is unmistakable: a brief dependency blip, then load arriving in waves — at t+1s, t+2s, t+4s — each wave re-knocking the service down precisely as it stands up. The dependency recovered in seconds; your retry configuration extended the outage by an hour. Jitter is not optional seasoning; it is the difference between recovery and resonance.
The tradeoff sheet
- Problem solved
- One slow dependency consuming every thread, connection and worker upstream of it, so a partial failure becomes a total one.
- Rejected, and why
- Generous timeouts and unlimited retries are the default and are how outages spread. Simply provisioning more capacity buys minutes and makes the eventual collapse larger.
- The trade
- Requests fail fast that might have succeeded slowly, a breaker can trip on a blip, and every threshold is a number you tuned rather than derived.
- First to break at 10x
- Thread and connection pools, exactly as designed — the point is that they break in a bounded way. Untuned, retries amplify load onto a dependency already failing.
- What it does to the bill
- Nothing to run, and it is the difference between one degraded service and a full outage. The cheapest resilience on the page.
- Day-2 operations
- Breaker state transitions belong in your dashboards and your logs. A breaker that has been open for a day is a dependency nobody has looked at.
When this actually happened
A brief network disruption meant storage servers could not reach the metadata service inside their timeout. They retried — and disqualified themselves from serving — which raised load on the metadata service, which made more servers time out. A textbook retry storm, and note the recovery: AWS could not add capacity until they first *paused* requests to the metadata service. Shedding load was the prerequisite for fixing it.
Going deeper
- Release It! Michael Nygard, 2nd ed. 2018
Where circuit breakers, bulkheads and the stability patterns in this lesson were named and argued for. - Timeouts, retries and backoff with jitter Amazon Builders’ Library
The practical version, including why full jitter beats the backoff scheme you would have written.