Circuit Breaker States and Transitions
You'll learn: How circuit breakers move between closed, open, and half-open states to protect your system from cascading failures.
The Three States
Think of a circuit breaker like a smart safety switch that monitors how well a downstream service is performing.
Closed State
This is normal operation. Requests flow through freely to the downstream service. The circuit breaker quietly counts failures. If failures stay below a threshold, everything continues smoothly.
Open State
When failures exceed your threshold (say, 5 failures in 10 seconds), the breaker "trips" open. Now it immediately rejects requests without even trying the failing service. This prevents wasting resources on calls that will likely fail and gives the downstream service time to recover. After a timeout period (e.g., 30 seconds), the breaker moves to half-open.
Half-Open State
The circuit breaker cautiously tests if the service has recovered by allowing a limited number of requests through (often just one or a few). If these succeed, the breaker closes and normal operation resumes. If they fail, it snaps back open for another timeout period.
State Transition Flow
Closed → Open: Triggered when failure rate crosses threshold
Open → Half-Open: Triggered automatically after timeout expires
Half-Open → Closed: Triggered when test requests succeed
Half-Open → Open: Triggered when test requests fail
This cycle prevents your application from repeatedly hammering a struggling service while providing automatic recovery when things improve.
Key Takeaway: Circuit breakers transition between closed (normal), open (fast-fail protection), and half-open (testing recovery) states to provide automatic fault detection and recovery without manual intervention.