QA
Beginner LevelSystem Design & Architecture

What is the Circuit Breaker Pattern and how does it prevent cascading system failures?

❓ Interview Prompt: Explain Circuit Breakers, Closed, Open, and Half-Open states, failure thresholds, and preventing cascading failures across microservices.

The Circuit Breaker Pattern wraps remote network calls to prevent a failing downstream service from causing cascading failure across an entire system:

3 States:

1
🟒 Closed (Normal): Requests pass through to the downstream service.
2
πŸ”΄ Open (Failing): Downstream error threshold exceeded. Circuit trips open immediately; all subsequent calls fail fast or execute fallbacks without calling the failing service!
3
🟑 Half-Open (Testing): After a cooldown timer, limited trial requests test if the downstream service has recovered.

Code Implementation Example

markdown
Circuit Breaker State Machine:

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  (Failures > Threshold)  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚  Closed  β”‚ ───────────────────────> β”‚   Open   β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β–²                                      β”‚ (Cooldown Timer)
       β”‚        (Trial Success)  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
       └──────────────────────── β”‚Half-Open β”‚ <β”˜
                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
πŸ’‘Circuit Breaker state transition machine.
🎯 Interview Key Takeaway

Wrap downstream network calls with Circuit Breakers to fail fast and prevent cascading microservice outages.

#System Design#Circuit Breaker#Resilience#Fault Tolerance#Beginner
Back to all System Design & Architecture Questions→

More System Design & Architecture Interview Questions

Beginner LevelSystem Design & Architecture

Explain the CAP Theorem and PACELC Theorem with real-world database examples.

Beginner LevelSystem Design & Architecture

What is Vertical Scaling (Scale Up) vs Horizontal Scaling (Scale Out)?

Beginner LevelSystem Design & Architecture

How do Load Balancers distribute traffic (Round Robin, Least Connections, IP Hash)?