Failing downstream service + retries = amplified failure = cascade. Circuit breaker trips fast, saves you, probes for recovery. Universal microservice pattern.
CLOSED state
Normal. Requests flow. Failure counter increments on errors. Threshold reached → OPEN.
CLOSED state
Normal. Requests flow. Failure counter increments on errors. Threshold reached → OPEN.
OPEN state
Every request fails fast with CircuitOpenException. No downstream calls. Recover time = configured duration.
HALF-OPEN state
After OPEN duration, one probe request allowed. Success → close. Failure → open again (with longer duration).
Configuration
Failure threshold (5-10). Window (30s). Open duration (60s). Tune per downstream. Aggressive for critical, relaxed for optional.
Fallbacks
When circuit is OPEN, return cached value, degraded response, or 'service unavailable'. Never return random errors.