Lesson 5.2 · 15 min
Circuit breakers
Break a dependency for 20 seconds and watch a shared thread pool drain, then add a circuit breaker and a bulkhead and replay the same minute.
The idea in plain words
A circuit breaker in your house cuts power when something shorts, before the wires catch fire. In software it stops calling a failing service for a while, so your own servers don’t get stuck waiting and the other service gets time to recover.
The problem it solves
When a service you depend on is down or very slow, every call to it waits until it times out. Your threads fill up with waiting calls and your service fails too, even for features that don’t need the broken one.
How it works
- Wrap calls to the dependency and count recent failures.
- If failures pass a threshold, the breaker opens: calls fail immediately without being sent.
- Return a fallback instead: cached data, a default, or a clear error.
- After a pause, let a few test calls through (half-open).
- If they succeed, close the breaker and resume; if not, open it again.
Example
The recommendations service hangs. Without a breaker, product pages wait 10 s for it and the whole site slows. With one, after a few failures pages skip recommendations instantly and load in 200 ms; when the service recovers, recommendations come back on their own.
Key terms
- Closed
- Normal: calls go through and failures are counted.
- Open
- Too many failures: calls fail immediately without being sent.
- Half-open
- After a pause, a few test calls go through to see if the service is back.
- Fallback
- What you return instead: cached data, a default, or a clear error.
- Bulkhead
- Separate thread pools per dependency, so one slow service can’t use them all.
In this lesson you'll learn
- How a hanging dependency drains a thread pool and takes down unrelated endpoints.
- How a circuit breaker's closed, open and half-open states stop that, and how bulkheads contain it.
- Which fallback to return per feature when the breaker is open.
Sections
- Theory: a dependency hangs
- Theory: compare protections
- Design: pick a fallback
- Check yourself
Cheat sheet
| Closed | calls flow; count failures |
|---|---|
| Open | fail fast for a cool-down |
| Half-open | a few probes decide |
| Bulkhead | separate pool per dependency |
| Threads needed | rate × time each call is held |
The interactive simulations and the quiz load with JavaScript.