Resilience Patterns
In a system with hundreds of machines and dozens of services, something is always broken. A disk is failing, a deployment is half done, a database is in the middle of a failover, a network link is dropping packets. That's not a sign of a badly run system; it's arithmetic. If each of 1,000 machines fails once every three years, you lose about one machine a day.
So the question in a design interview isn't "what if something fails?" but "what does the rest of the system do when it does?" Interviewers ask it in many forms: what happens if the payment provider is slow? If the recommendation service is down? If traffic triples? If a whole region goes dark? The tools for answering are a small set of patterns, and the senior skill is knowing how they fit together and how each one can make things worse when used carelessly.
We'll build up in the order failures actually unfold:
- How a small failure becomes a big one: slow dependencies and cascading failures.
- The patterns for each call: timeouts, retries, circuit breakers and fallbacks.
- The patterns for each service and the system: bulkheads, backpressure and load shedding, health checks, and disaster recovery across regions.
How Systems Actually Fail
The failure that hurts most is rarely a clean crash. A crashed service refuses connections immediately, callers get an error in a millisecond, and load balancers route around it. The dangerous failure is a slow one.
Picture a product page service that calls a reviews service. Normally reviews answer in 20 ms. Then the reviews database starts struggling, and reviews calls take 10 seconds. Here's what follows:
- Each product page request now holds a thread (or connection, or memory) for 10 seconds instead of 20 ms. The product service has a pool of 200 worker threads. At 500 requests per second, they're all busy within half a second.
- Now the product service can't serve any request, including ones that don't need reviews. It's effectively down, even though nothing is wrong with it.
- The services that call the product service see timeouts too, fill their own pools, and the failure spreads upward.
- Clients and services retry the failed requests, multiplying the load on everything that is still barely standing.
This is a cascading failure: a problem in one non-critical dependency takes down the whole system. Almost every pattern below exists to break one link of that chain.