Notesfoundations๐ฑ seedling
Circuit Breaker
Also: Circuit Breaker Pattern ยท Outlier Detection
A circuit breaker wraps calls to a dependency and, once failures cross a threshold, trips open so later calls fail instantly without being sent. After a cool-down it lets a trial call through (half-open) and closes again if it succeeds.
Why it exists
When a dependency is properly down, retries and waiting only waste the caller's threads and pile load on the thing that is trying to recover. A breaker turns a slow, failing dependency into a fast, contained error.
How it works
- Closed: calls pass through; the breaker counts failures and timeouts over a window.
- Open: failure rate crossed the threshold. Calls fail immediately (or get a fallback) for a cool-down period.
- Half-open: after the cool-down, one or a few trial calls go through. Success closes the breaker; failure reopens it for another cool-down.
- Pairs with a fallback: cached data, a default, a degraded page.
Trade-offs
| Gains | Costs |
|---|---|
| callers keep their resources | thresholds and cool-downs need tuning |
| dependency gets room to recover | trips on blips can cause minutes-long feature outages |
| fast, predictable failures | fallback logic to build and test |
In practice
- Hystrix popularised breakers in Java; it is in maintenance mode, and new code tends to use resilience4j or adaptive concurrency limits.
- Envoy "circuit breaking" is per-cluster concurrency caps (1,024 connections, pending and active requests by default; 3 concurrent retries), and outlier detection ejects a single host after 5 consecutive 5xx responses.
Pitfalls
- One breaker in front of a sharded or multi-host backend: one bad shard trips it and cuts off the healthy ones. Break per host or per shard.
- A breaker whose open state has never been exercised: the fallback path is probably broken.
Connections
- Part of
- Foundations
- Learn first
- Timeout
- In real systems
- Envoy
Recall
These cards are also in your review deck, scheduled with spaced repetition.