How the Circuit Breaker pattern works in circuit_breaker
masterThe CircuitBreaker mixin implements Michael Nygard's pattern to protect your application from failing remote services. It manages three states:
- Closed: The default state. All calls to the protected method are allowed to proceed. Consecutive failures are tracked.
- Open: Triggered when the
failure_thresholdis reached or aninvocation_timeoutoccurs. In this state, all calls immediately fail by raising aCircuitBrokenExceptionwithout attempting to call the service. - Half Open: Occurs after the
failure_timeoutduration has elapsed while in the Open state. The next call is allowed through. If it fails, the circuit immediately returns to the Open state. If it succeeds, the circuit returns to the Closed state and the failure count is reset.