Question #22 of 60•Microservices•Medium• ~3 min read

How does the Circuit Breaker Pattern prevent cascading failures in microservices?

Executive Takeaway

Analyze state transitions (Closed, Open, Half-Open) in Resilience4j and Hystrix to isolate failing downstream services.

Architectural Breakdown & AnalysisFAANG Aligned

When a downstream microservice is slow or failing, continuing to send requests exhausts caller thread pools, crashing caller services.

Circuit Breaker States

  1. CLOSED (Normal Operation):

Requests pass through. Failure counts are tracked in a sliding window.

  1. OPEN (Tripped Failure State):

If error rate exceeds threshold (e.g. 50%), circuit trips to OPEN. Requests fail immediately with a fallback response without calling downstream.

  1. HALF-OPEN (Trial Probe State):

After a sleep window (e.g. 30s), limited trial requests are allowed through. If successful, circuit resets to CLOSED; if failed, returns to OPEN.

json
{
  "slidingWindowSize": 100,
  "failureRateThreshold": 50.0,
  "waitDurationInOpenState": "30s"
}
NOTE — Resiliency Ecosystem

Use libraries like Resilience4j (Java) or gobreaker (Go) alongside graceful fallbacks (e.g., return cached catalog data).

Key Architectural Comparison

Circuit Breaker StateTraffic Allowed Downstream?Transition ConditionAction on Failure
CLOSED (Normal)100% of requests pass through.Failure rate exceeds threshold (e.g. 50%).Trip circuit to OPEN.
OPEN (Tripped)Zero requests (Fails fast immediately).Cooldown sleep window expires (e.g. 30s).Transition to HALF-OPEN.
HALF-OPEN (Trial)Canary sample of requests (e.g. 5%).Canary requests succeed $\rightarrow$ CLOSED; any fail $\rightarrow$ OPEN.Returns fallback response.
Previous QuestionWhat are the trade-offs of Cache Eviction Policies (LRU, LFU, ARC) in Redis & Memcached?Next Question How do Master-Replica, Multi-Master, and Leaderless Database Replication operate?

Continue Learning on Being SDE

Explore deep-dive system architecture modules, low-level object-oriented designs, and interview cheat sheets.