System Design (50 Qs)•Part 3: Distributed Transactions, Consensus & Reliability (26 - 36)
Circuit Breaker Pattern (Netflix Hystrix / Resilience4j).
In Simple Words: Prevent cascading failures when a downstream microservice is down. Instead of exhausting worker threads on blocking timeouts, the Circuit Breaker trips to OPEN state and fails fast.
- CLOSED: Requests flow normally. Failures increment failure counter.
- OPEN: Error threshold exceeded. Requests fail immediately with fallback without network hop.
- HALF-OPEN: After sleep window, allows trial requests. If successful, resets to CLOSED.
Architecture Flowchart
stateDiagram-v2
[*] --> Closed
Closed --> Open: Failure Rate > Threshold (e.g. 50%)
Open --> HalfOpen: Sleep Window Elapsed (e.g. 30s)
HalfOpen --> Closed: Trial Requests Succeed
HalfOpen --> Open: Trial Request Fails