Protect your system from cascading failures with the Circuit Breaker pattern. Watch the three-state finite state machine (Closed, Open, Half-Open) respond to service health changes.
Requests pass through normally. The failure counter tracks errors. If failures exceed the threshold, the breaker trips to Open.
The Circuit Breaker pattern prevents cascading failures in distributed systems. It wraps calls to an external service and monitors for failures. Like an electrical circuit breaker that trips to prevent damage, it stops sending requests to a failing service, giving it time to recover. The pattern uses a three-state finite state machine: Closed (normal), Open (rejecting), and Half-Open (testing).
Normal operation. Requests pass through. Failures are counted. Trips to Open when threshold is exceeded.
Fail-fast mode. All requests are immediately rejected. A timeout timer runs. Transitions to Half-Open when timer expires.
Testing mode. Limited probe requests are sent. Success closes the breaker. Failure re-opens it.
| Parameter | Current | Typical | Description |
|---|---|---|---|
| Failure Threshold | 3 | 3-5 | Number of failures before tripping to Open |
| Recovery Timeout | 10t | 30-60s | Time in Open before transitioning to Half-Open |
| Half-Open Probes | 2 | 1-3 | Successful probes needed to close the circuit |
The Circuit Breaker pattern was popularized by Michael Nygard in "Release It!" and later by Netflix Hystrix. It is now a standard pattern in microservices architectures. Spring Cloud Circuit Breaker, Resilience4j, Polly (.NET), and gobreaker (Go) are popular implementations. Service meshes like Istio and Envoy provide circuit breaking at the infrastructure level, and cloud providers like AWS offer circuit breaker support in their App Mesh and API Gateway services. It is commonly used for database connections, HTTP calls, message queue producers, and any external service dependency.