Circuit Breaker Integration for Automatic Degradation
Circuit Breakers as Degradation Triggers
Circuit breakers (components that stop calling failing services) provide automatic degradation triggers. When a circuit opens after 50% error rate over 10 seconds, the system switches to fallback behavior. Fallback executes in less than 1ms versus waiting for timeout on failed calls.
Fallback Registration
Each circuit breaker should have a registered fallback: breaker.call(primary, fallback). When open, fallback executes immediately. Match fallback signature to primary for seamless substitution. For recommendations: primary fetches personalized, fallback returns cached popular items.
Multi-Level Circuit Breakers
Large systems need breakers at multiple levels: Client level (each instance tracks dependencies), Service level (aggregate failure rates), Feature level (per feature regardless of topology). Feature circuit trips when any backend fails, triggering feature-level fallback.
Half-Open State and Recovery
In half-open state, one request tests primary while others use fallback. Success closes circuit; failure reopens. Configure interval: 30 seconds for transient issues, 5 minutes for infrastructure. Gradual recovery: 10% traffic initially, ramping to 100% over 60 seconds.
Timeout Coordination
If timeout is 5 seconds and circuit trips after 5 failures, worst case degradation takes 25 seconds. Too slow. Reduce timeout to 1 second, trip after 3 failures for 3 second degradation.