Circuit Breaker Pattern
The circuit breaker pattern is a resilience mechanism that detects when a downstream service is failing and stops sending it requests — "opening" the circuit — to prevent cascading failures from propagating through a distributed system.
The circuit breaker pattern is a resilience mechanism that detects when a downstream service is failing and stops sending it requests — "opening" the circuit — to prevent cascading failures from propagating through a distributed system.
What the diagram shows
This state diagram models the three states a circuit breaker transitions between:
- Closed (normal operation): requests flow through freely. The breaker counts failures within a rolling window. Each successful call resets the failure counter. - Open (fault isolated): when the failure count exceeds the configured threshold (e.g., 5 failures in 10 seconds), the breaker trips open. All subsequent requests fail immediately without ever reaching the downstream service — a technique called "fail fast." This protects the downstream from being hammered while it recovers. - Half-Open (probe state): after a configurable timeout (e.g., 30 seconds), the breaker transitions to Half-Open and allows a single test request through. If the test request succeeds, the circuit closes and normal operation resumes. If it fails, the breaker returns to Open for another timeout cycle.
Why this matters
Without a circuit breaker, a slow or failing downstream service causes callers to pile up waiting for timeouts — exhausting thread pools and connection pools in the caller, which then starts failing its callers. The failure cascades upward. The circuit breaker breaks this chain by failing fast at the first sign of consistent downstream failure.
Netflix's Hystrix library popularized this pattern, and it is now built into service meshes like Istio and Linkerd. In practice, circuit breakers work best alongside Request Retry Logic — retries handle transient failures, while circuit breakers handle sustained outages. The Bulkhead Pattern complements circuit breakers by isolating thread pools so that one failing dependency doesn't exhaust resources for others.