Module 5 · Distributed systemsLesson 57 of 886 minIntermediate

Fault tolerance

A fault-tolerant system keeps working when parts of it fail, because no single part is irreplaceable.

Try it

Set traffic so three servers are comfortably busy. Crash one with health checks off, then on. Then try with only two servers, so there's no spare capacity.

Every component will fail eventually: disks, servers, network links, whole data centres, and your own deploys. Fault tolerance means designing so that a failure of one part doesn't take down the whole.

The building blocks

  • Redundancy: run at least two of everything critical (servers, load balancers, database replicas), ideally in different failure zones (racks, availability zones).
  • Spare capacity (N+1): if you need N servers for peak load, run N+1, so losing one still leaves enough. At bigger scale, N+2 or more.
  • Detection: health checks and heartbeats spot failures within seconds.
  • Automatic failover: route traffic away from failed parts without waiting for a human.
  • Isolation: timeouts, circuit breakers and bulkheads stop one failure from spreading to callers.

Graceful degradation

Not everything is equally important. When parts fail, keep the core working:

  • Product pages still load if recommendations are down.
  • Checkout works even if loyalty points can't be shown.
  • Serve slightly old cached data rather than an error.

Test it

Fault tolerance you've never exercised probably doesn't work. Teams practise with:

  • Game days: deliberately fail something in a controlled way.
  • Chaos engineering: tools like Chaos Monkey randomly terminate instances in production to make sure the system copes.

Failure domains

Spares only help if they don't fail together. Two servers in the same rack share a power supply; two regions don't. Spread replicas across availability zones, and for the most critical systems, across regions.

Quick check

Three servers each run at 80% busy. One crashes. What happens?