Resilience & Service PatternsGraceful DegradationMedium

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.

💡 Key Insight: Well-designed fallbacks should be indistinguishable to users. If recommendations look obviously different during fallback, users notice unreliability. Make fallbacks blend naturally.

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.

💡 Key Takeaways
Circuit breakers trigger automatic degradation when failure thresholds are reached
Each circuit breaker should have a registered fallback that executes immediately when open
Coordinate timeout and circuit breaker settings - worst case degradation = timeout × failure threshold
📌 Interview Tips
1Show understanding of circuit breaker states: closed (normal), open (fallback), half-open (testing recovery)
2Mention gradual recovery: 10% traffic to primary, ramping to 100% over 60 seconds
3Multi-level circuit breakers (client, service, feature level) show architectural sophistication
← Back to Graceful Degradation Overview