The failure spiral
When a dependency slows or fails, callers keep retrying. Threads pile up waiting, the caller itself slows, and the failure spreads. This cascading failure can take down healthy services.
The breaker
A circuit breaker wraps calls to a dependency and tracks failures. It moves between three states:
- Closed: calls pass through normally.
- Open: after too many failures it trips, and calls fail fast without hitting the dependency.
- Half open: after a cooldown it lets a few probe calls through to test recovery.
Why fail fast helps
Failing fast frees threads and returns control quickly, often with a fallback like a cached value. The struggling dependency also gets breathing room to recover.
Key idea
A circuit breaker trips open after repeated failures so calls fail fast with a fallback, stopping cascading failure and letting the dependency recover.