When a downstream microservice is slow or failing, continuing to send requests exhausts caller thread pools, crashing caller services.
Circuit Breaker States
- CLOSED (Normal Operation):
Requests pass through. Failure counts are tracked in a sliding window.
- OPEN (Tripped Failure State):
If error rate exceeds threshold (e.g. 50%), circuit trips to OPEN. Requests fail immediately with a fallback response without calling downstream.
- HALF-OPEN (Trial Probe State):
After a sleep window (e.g. 30s), limited trial requests are allowed through. If successful, circuit resets to CLOSED; if failed, returns to OPEN.
{
"slidingWindowSize": 100,
"failureRateThreshold": 50.0,
"waitDurationInOpenState": "30s"
}Use libraries like Resilience4j (Java) or gobreaker (Go) alongside graceful fallbacks (e.g., return cached catalog data).
Key Architectural Comparison
| Circuit Breaker State | Traffic Allowed Downstream? | Transition Condition | Action on Failure |
|---|---|---|---|
| CLOSED (Normal) | 100% of requests pass through. | Failure rate exceeds threshold (e.g. 50%). | Trip circuit to OPEN. |
| OPEN (Tripped) | Zero requests (Fails fast immediately). | Cooldown sleep window expires (e.g. 30s). | Transition to HALF-OPEN. |
| HALF-OPEN (Trial) | Canary sample of requests (e.g. 5%). | Canary requests succeed $\rightarrow$ CLOSED; any fail $\rightarrow$ OPEN. | Returns fallback response. |