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β