29. Failures, Retries, Circuit Breakers
29.8 What are bulkheads?
At home: The AC, the fridge and the lights are on separate circuits. When the AC trips, the fridge keeps running. If everything shared one circuit, one faulty appliance would cut the whole house.
In the system: A bulkhead (named after a ship's watertight compartments) isolates resources so one failing dependency can't use up everything:
- Separate thread or connection pools per dependency.
- Separate instances for critical and non-critical traffic (checkout servers vs browse servers).
- Separate queues per customer tier or job type (Chapter 22).
- Cells: split the whole system into independent copies, each serving a subset of users, so a bad deploy or overload hits one cell, not everyone.
Figure: a slow dependency can only drown its own compartment.
In the chapter's code, recommendations slow to 5 seconds per call. With one shared pool of 200 threads, checkout needs 20 (payment) + 5 (inventory) + 500 (recommendations) = 525 threads: the pool is exhausted and checkout stops. With separate pools (60 for payment, 40 for inventory, 100 for recommendations), only recommendations runs out; its calls fail fast and the page shows bestsellers instead. Checkout keeps working.
Memory code: "Separate circuits: the AC can trip without spoiling the milk."