SysDesignAtlas

Failure Modes & Fault Tolerance

Partial failure is the defining property of distributed systems. Gray failures, cascading collapse, retry storms, and the design patterns that contain them.

CoreMedium12 min readfailureresiliencefault-tolerance
Confidence

#The defining difference

A single-machine program fails cleanly: it works or it crashes. A distributed system has a third state that doesn't exist on one machine — partial failure, where some components work, some don't, and you can't tell which.

This is the root of nearly every hard problem in this curriculum. When you send a request and get no response, you cannot distinguish between:

  • the request never arrived,
  • it arrived and the server died before processing,
  • it was processed and the response was lost,
  • everything is fine and it's just slow.

The first and second mean "safe to retry." The third means "retrying will duplicate the operation." You cannot tell them apart, ever — which is why idempotency isn't an optimization, it's a requirement.

#The eight fallacies

The classic list of assumptions that are false in distributed systems, and each one is a design constraint:

  1. The network is reliable → packets drop; every call needs retries and timeouts.
  2. Latency is zero → designs that make many small calls are slow; batch and co-locate.
  3. Bandwidth is infinite → payload size matters; paginate and compress.
  4. The network is secure → encrypt in transit, authenticate service-to-service.
  5. Topology doesn't change → nodes come and go; use service discovery (a registry where services look up each other's current addresses), not hardcoded IPs.
  6. There is one administrator → many people change many machines, so their configuration slowly drifts apart; make deploys reproducible.
  7. Transport cost is zero → traffic between availability zones, and data leaving to the internet (egress), cost real money.
  8. The network is homogeneous → maximum packet sizes (MTUs), protocols, and latencies differ across paths.

#Gray failure — the worst kind

Binary failure is easy: a node dies, health checks fail, traffic reroutes, done.

Gray failure is when a node is technically alive but functionally broken. It answers health checks with 200 OK while serving real requests at 40× normal latency, or returning empty results, or accepting writes and silently dropping them. The disk is failing but hasn't failed. The runtime's garbage collector — the pause where it reclaims unused memory — is freezing the process for eight seconds at a time. A downstream dependency it needs is down but its own /health doesn't check that.

This is worse than a crash because the system's failure detection actively works against you: the node is kept in rotation, receives its full share of traffic, and poisons a fraction of every user's requests.

Defenses:

  • Deep health checks that exercise real dependencies, not return 200. But keep them cheap and be careful — a deep check that fails when a shared dependency wobbles will remove your entire fleet at once.
  • Health check the outcome, not the process. Take a node out of rotation when its real latency or error rate is far worse than its peers' — outlier detection, built into service meshes (the proxy layer that carries traffic between services) and many load balancers. That catches gray failure that a liveness probe — a check that only asks "is the process running?" — never will.
  • Client-side awareness. Load balancing on measured latency, and a separate circuit breaker per endpoint, so one bad instance gets cut off without cutting off the healthy ones.
  • Fail fast on your own degradation. A node that knows its dependency is down should say so rather than hang.

#Cascading failure

How most large outages actually happen. The pattern is a feedback loop:

  1. One node fails or slows
         ↓
  2. Its traffic redistributes to the survivors
         ↓
  3. Survivors now run above their safe utilization
         ↓
  4. Their latency rises; queues fill; they slow further
         ↓
  5. Clients time out and RETRY, multiplying load
         ↓
  6. Next node crosses its limit and fails
         ↓
      back to step 2, faster each time

The system doesn't degrade gracefully — it collapses in seconds, and it often stays collapsed after the original trigger is gone, because the retry load alone is now enough to keep it down. That self-sustaining state has a name — a metastable failure — and it accounts for a surprising share of major cloud outages.

Containment patterns:

  • Load shedding — reject excess work fast, at the edge, before it consumes resources. A quick 429 ("Too Many Requests") costs almost nothing; a request that times out after 30 s has consumed a connection, a thread, and memory the whole time.
  • Circuit breakers — stop calling a failing dependency entirely for a cooldown, then probe with a trickle. Prevents you from being dragged down and gives the dependency room to recover.
  • Bulkheads — separate thread pools / connection pools per dependency, so one slow downstream can't consume every worker. Named after the sealed compartments in a ship's hull: a leak floods one compartment, not the whole ship.
  • Capacity headroom — run at 60–70%, not 95%, so losing a node doesn't push survivors past the knee — the utilisation point beyond which latency climbs steeply (see queueing theory).
  • Jittered exponential backoff — see below.

#Retry storms and the jitter fix

Retries are necessary and are also the most common way engineers turn a small problem into an outage.

Naive retry: a service returns errors, 10,000 clients retry immediately, offered load triples, the service now cannot recover because it's being retried. This is a self-sustaining outage.

Three things make retries safe:

1. Exponential backoff with jitter. Backoff means waiting longer before each successive retry — 1 second, then 2, then 4. Jitter means adding a random amount to that wait. Without jitter, clients that failed at the same moment retry at the same moment, in synchronised waves that hit an already-struggling service together. Full jitter is the standard fix:

  no jitter:    delay = base × 2^attempt
                → all clients retry at t = 1s, 2s, 4s, 8s  (thundering herd)

  full jitter:  delay = random(0, base × 2^attempt)
                → retries spread smoothly across the window

2. Retry budgets. Cap retries as a fraction of total traffic — e.g. retries may never exceed 10% of requests. Under widespread failure, retries stop entirely rather than amplifying. This is far more robust than per-request retry limits. "Up to 3 retries per request" still lets every failing request become 4 requests — so when everything is failing, total load quadruples across the whole fleet.

3. Don't retry at every layer. If the client retries 3×, the gateway retries 3×, and the service retries 3× against the database, one user action becomes 27 database queries. Retry at one layer — usually the one closest to the user that can still make a meaningful choice — and pass failures through elsewhere.

#Timeouts

Every remote call needs one. A call without a timeout is a resource leak waiting for a bad day.

Choosing values: set the timeout near the p99.9 of the healthy latency distribution — the time within which 999 of every 1,000 requests finish when the system is working normally. Too tight and you fail requests that would have succeeded, adding load through retries. Too loose and you hold resources through an outage.

Deadline propagation is the technique that separates good designs from naive ones. Rather than each service having an independent timeout, pass a deadline down the call chain:

   Client: "answer by T+300ms"
      → Gateway (spends 20ms): "answer by T+280ms"
         → Service A (spends 50ms): "answer by T+230ms"
            → Service D: sees only 230ms remain; if its work
              takes 400ms it fails IMMEDIATELY rather than
              doing work whose result nobody will wait for

Without deadline propagation, backends routinely complete expensive work for callers that gave up long ago — burning capacity precisely when capacity is scarce.

#Failure detection is a guess

You can never know a remote node has failed; you can only observe that it hasn't responded. Timeout too short → you declare healthy nodes dead, causing needless failovers and possibly split brain, where two halves of a cluster each decide they're in charge and both accept writes. Timeout too long → real failures go undetected and users suffer.

There's no correct answer, only a tradeoff. Adaptive detectors (phi accrual, used by Cassandra and Akka) improve on a fixed rule like "no heartbeat for 5 s means dead". They learn how regularly each node's heartbeats normally arrive, then output a suspicion level: how unlikely the current silence would be if the node were healthy. Each caller picks its own threshold — a failover system might wait for high certainty, a load balancer might act on mild suspicion. See Gossip & Failure Detection.

#Designing for failure — the checklist

Run any design through these questions. In an interview, volunteering two or three of them unprompted is worth a lot:

  • What happens when each component dies? Walk the diagram, kill each box, describe the behavior.
  • Is any component a single point of failure? Including the "boring" ones — the config service, the DNS entry, the certificate, the single Redis holding your locks.
  • What's the blast radius? Does one bad shard take down one shard's users or everyone? Cell-based architecture and shuffle sharding exist to bound this.
  • Can it self-heal, or does it need a human? Humans take 15+ minutes at 3am. That's your RTO floor if a human is in the loop.
  • What's the behavior under overload? "It gets slow" is a wrong answer. "It sheds load at the edge and serves the remaining 80% at normal latency" is right.
  • Does it degrade gracefully? Can you serve stale cache, disable a non-essential feature, or return partial results instead of failing entirely?
  • What's the recovery path? After the outage, does traffic returning all at once re-break it? (Cold caches and empty connection pools make recovery its own overload event — the "thundering recovery" problem.)

#Graceful degradation, concretely

The most valuable pattern here, because it is product-aware rather than purely technical. Rank your features by criticality and define what happens when each dependency fails:

Dependency downNaive behaviorDegraded behavior
Recommendation service500 on homepageShow trending/popular list
Cache clusterHammer DB until it diesServe stale entries; shed low-priority reads
Search indexSearch page errorsFall back to prefix match on primary DB
Image CDNBroken pageServe placeholder, text still renders
Analytics pipelineBlocks checkoutFire-and-forget; drop events
Payment providerCheckout failsQueue the order, capture asynchronously, notify

The pattern in every row: the core transaction survives; the periphery is sacrificed. Deciding which is which is a product decision, and making it explicitly — rather than letting the failure decide for you — is the whole idea.

#Check yourself

A request gets no response. Why does that make idempotency a requirement?Show answer
The request may never have arrived, may have died mid-processing, or may have succeeded with the reply lost — and you can't tell which. Retrying must be safe even if the work already happened.
What is a gray failure, and why is it worse than a crash?Show answer
A node that passes health checks while serving slow, empty or wrong responses. Failure detection keeps it in rotation, so it poisons a share of every user's requests.
How do you catch gray failures that a liveness probe misses?Show answer
Judge outcomes, not process: eject instances whose error rate or p99 deviates from the fleet (outlier detection), with a cap so you never eject too many at once.
Describe the feedback loop behind a cascading failure.Show answer
One node slows or fails, its traffic moves to the survivors, they pass their safe utilisation and slow down, clients time out and retry, and the next node fails — faster each round, often staying down after the trigger is gone.
Why add jitter to exponential backoff?Show answer
Without it, clients that failed together retry together, in waves that hit a struggling service at once. Full jitter — a random wait up to the backoff — spreads retries out.
Why are retry budgets more robust than per-request retry limits?Show answer
A budget caps retries as a share of all traffic (say 10%), so under widespread failure retries stop instead of multiplying load across the whole fleet.
Why can't you choose a "correct" failure-detection timeout?Show answer
Too short and healthy nodes are declared dead, causing needless failovers or split brain; too long and real failures go unnoticed. Adaptive detectors like phi accrual output a suspicion level instead.
What does graceful degradation look like when the payment provider is down?Show answer
Keep the core transaction alive: queue the order, capture payment later, and tell the customer — rather than failing checkout. Decide what to sacrifice ahead of time.

#What to carry forward

  • Partial failure is the defining property of distributed systems: silence can't tell you what happened, so retries must be safe.
  • Gray failures pass health checks; detect them by outcomes — latency and error outliers.
  • Cascades come from redistributed load plus retries; contain them with load shedding, circuit breakers, bulkheads and headroom.
  • Make retries safe: jittered backoff, a fleet-wide retry budget, and retries at one layer only.
  • Propagate deadlines, and decide in advance what degrades so the core transaction survives.
00:00
/ 12m