Circuit Breakers & Bulkheads
Definition
Circuit breaker
- In plain English
- A circuit breaker stops calling a failing dependency for a while after too many errors, failing fast instead.
- Think of it like
- It is like a household fuse that trips to stop damage, then gets reset.
Bulkhead
- In plain English
- A bulkhead gives each kind of work its own limited pool of resources so one slow part can't use them all.
- Think of it like
- It is like a ship's watertight compartments that keep one leak from sinking the whole ship.
Why it exists
Payments stop responding, but every checkout waits ten seconds. Waiting work consumes the workers needed by healthy features.
Timeouts limit each wait. You also need to stop calling a dependency that keeps failing and reserve capacity for critical work.
How it works
Closed, open and half-open
- In plain English
- A breaker is closed when calls flow, open when calls are blocked, and half-open when a few test calls check for recovery.
- Think of it like
- Like a shop door that is open, locked, or opened a crack to peek outside.
Fallback
- In plain English
- A fallback is a simpler answer used when the real one isn't available.
- Think of it like
- Like a cached weather forecast when the live one fails.
The breaker starts closed, opens after failures, then allows half-open test calls that either close or reopen it.
- Measure failures
Count recent errors and require enough calls before using a percentage threshold.
- Open
Stop calling the dependency during a cool-down period.
- Respond
Return a useful fallback or a clear temporary error.
- Probe
Allow a few half-open test calls, then close on success or reopen on failure.
Requests go to separate pools with twenty door-unlock workers and five analytics workers.
Examples
Fail fast during payment trouble
Payments fail on half the calls in a ten-second window, so the breaker opens.
Require a minimum sample, such as 20 calls, before applying the 50% threshold. One failed call should not establish a reliable percentage.
Checkout reaches an open breaker, confirms an existing seat hold, and returns a temporary payment error.
Say seats are held for ten minutes only after the booking system confirms that hold. A fallback cannot invent a reservation.
The insight
Failing fast protects users and server capacity.
Plan with a reduced location service
The address-to-map lookup service fails, so the breaker opens.
A delivery address reaches an open lookup breaker and uses the postcode centre to build an approximate route.
Mark the location as approximate and let staff verify it. A postcode centre cannot replace an exact doorstep location.
The insight
A fallback can keep a reduced service running.
Protect door unlocks
Slow analytics calls once occupied every worker and delayed door unlocks.
Give unlocks twenty workers and analytics five separate workers. Analytics can fill its own pool without taking the unlock pool.
Keep shared database connections and other limits separate where needed. Worker pools cannot protect a shared resource they both exhaust.
The insight
Isolate critical work from non-critical work.
Trade-offs
Pros
- Fails quickly during repeated errors.
- Lets dependencies recover.
- Contains resource exhaustion.
Cons
- Thresholds need tuning.
- Brief failures can trip a breaker.
- Fallbacks may return incomplete data.
Use when
- Remote calls can fail or slow down.
- Critical work shares resources with optional work.
Avoid when
- An in-process call needs only error handling.
- A fallback would claim an action happened when it did not.
Quick check
Takeaways
- Circuit breakers fail fast when a dependency is down.
- Bulkheads stop one slow part taking every resource.
- Pair both with timeouts and fallbacks.