Circuit Breaker Pattern

Closed/Open/Half-open states, cascading failure prevention, and implementations with Hystrix and Resilience4j.

Overview

Overview The Circuit Breaker pattern prevents an application from repeatedly trying to call a service that is likely to fail. Just like an electrical circuit breaker that trips to prevent a house fire, this pattern detects failures and short-circuits requests to a failing service, giving it time to recover.

Without circuit breakers, a single failing service can bring down an entire microservices system through cascading failures. When Service A depends on Service B, and Service B is slow or down, Service A's threads get blocked waiting for responses. As threads exhaust, Service A stops responding, and the failure cascades to every service that depends on A.

Netflix pioneered this pattern at scale with Hystrix, handling billions of requests daily across hundreds of services. While Hystrix is now in maintenance mode, the pattern lives on in Resilience4j, Istio, and Envoy. In interviews, expect to draw the state machine, discuss threshold tuning, and explain how the pattern prevents cascading failures.

Key concepts

  • Closed, Open, and Half-open states
  • Failure threshold and sliding window
  • Cascading failure prevention
  • Fallback strategies
  • Monitoring and alerting on state transitions
  • Hystrix and Resilience4j implementations
  • Timeout management
  • Bulkhead integration

Interview questions

  • Explain the circuit breaker state machine and transitions.
  • How do cascading failures happen and how do circuit breakers prevent them?
  • What fallback strategies should you use when the circuit is open?
  • Compare Hystrix and Resilience4j, and when would you use each?

Sign up free to read the full topic

More Microservices topics

Start free on Cariara · Coding problems · System design studio