Circuit Breaker
A resilience pattern that trips open to fail fast and serve fallbacks when a downstream dependency exceeds error thresholds, preventing thread exhaustion and cascading outages
Table of Contents
Interactive Playground
Tap or drag to interact with the demoWhat is Circuit Breaker?
A resilience pattern that trips open to fail fast and serve fallbacks when a downstream dependency exceeds error thresholds, preventing thread exhaustion and cascading outages. It is a core concept in Observability & Reliability within Cloud / DevOps.
Core Principles
Inspired by electrical circuit breakers, this resilience pattern protects distributed systems from cascading failures. When a downstream dependency slows down or errors out, callers waiting on long timeouts quickly exhaust their own thread pools and bring down the entire platform.
A Circuit Breaker monitors failure rates via a three-state machine: Closed (normal flow), Open (tripped—immediately fail fast or return a fallback without calling the broken service), and Half-Open (after a cooldown, allow a few probe requests to verify recovery before closing again).
Practical Takeaways
- Design graceful fallbacks: Rather than failing an entire page with HTTP 500 when a non-critical widget trips, serve cached data or omit the optional section cleanly.
- Set a minimum request volume: Require a minimum sample size (e.g., at least 20 requests in a 10s sliding window) before tripping so a single stray error during low traffic does not open the breaker prematurely.
- Pair with strict timeouts and bulkheads: Circuit breakers rely on tight timeouts to detect slow failures quickly and work best alongside bulkhead resource isolation.
Notable Examples
- Resilience4j (JVM) & Polly (.NET): Standard application-level libraries combining circuit breakers, retries, and bulkheads.
- Envoy / Istio Outlier Detection: Automatically ejects unhealthy upstream pods at the service mesh layer without code changes.
- E-Commerce Product Pages: Trips open on failing review or recommendation services so core checkout stays 100% operational.