Circuit Breaker Status in Health Checks
Design health check components that expose circuit breaker states (closed, open, half-open) for external dependencies, enabling observability of resilience patterns.
Patterns
Detailed Explanation
Circuit Breaker Health Integration
Including circuit breaker states in health checks provides visibility into your service's resilience mechanisms and helps explain degraded behavior.
Response Component
{
"circuitBreakers": {
"payment-gateway": {
"status": "closed",
"failureRate": "2.5%",
"failureThreshold": "50%",
"successCount": 195,
"failureCount": 5,
"lastFailure": null
},
"email-service": {
"status": "open",
"failureRate": "75%",
"failureThreshold": "50%",
"successCount": 25,
"failureCount": 75,
"lastFailure": "2024-01-15T10:28:00Z",
"nextRetryAt": "2024-01-15T10:30:00Z"
},
"inventory-api": {
"status": "half-open",
"failureRate": "0%",
"testRequestsAllowed": 3,
"testRequestsCompleted": 1
}
}
}
Circuit Breaker States
| State | Meaning | Health Impact |
|---|---|---|
| Closed | Normal operation, requests flow through | UP |
| Open | Failures exceeded threshold, requests blocked | DEGRADED or DOWN |
| Half-open | Testing if service recovered | DEGRADED |
Mapping to Health Status
function deriveStatus(breakers) {
const states = Object.values(breakers).map(b => b.status);
if (states.some(s => s === 'open')) {
// Check if the open circuit is for a critical service
const criticalOpen = Object.entries(breakers)
.some(([name, b]) => b.status === 'open' && isCritical(name));
return criticalOpen ? 'DOWN' : 'DEGRADED';
}
if (states.some(s => s === 'half-open')) return 'DEGRADED';
return 'UP';
}
Why Expose Circuit Breaker State
- Debugging: Explains why certain features are unavailable
- Monitoring: Track circuit breaker transitions over time
- Alerting: Alert when circuits open on critical dependencies
- Capacity planning: Frequent circuit opens indicate under-provisioned dependencies
Best Practice
Separate critical and non-critical circuit breakers in your health mapping. An open circuit on your payment gateway is DOWN. An open circuit on your analytics service is DEGRADED at most.
Use Case
Resilient microservices that use circuit breaker patterns (Hystrix, Resilience4j, Polly) for external dependencies and need to surface circuit breaker state in observability dashboards.