Circuit Breaker Pattern

The Circuit Breaker pattern is used to prevent a service from repeatedly trying to execute an operation that is likely to fail. It’s like an electrical circuit breaker: if too many failures happen, the circuit “opens” to prevent further damage, and after a timeout, it can try again.

States of a Circuit Breaker:

  1. Closed: Everything works normally. Requests go through. If failures exceed a threshold, the breaker opens.
  2. Open: Requests are blocked, and a fallback method is executed. After a certain timeout, the breaker moves to half-open.
  3. Half-Open: Allows a few requests to test if the problem is resolved.

Why use it?


Hystrix Circuit Breaker

Hystrix is a library from Netflix that implements the circuit breaker pattern. Even if deprecated, it’s useful for learning because Resilience4j (the modern replacement) works similarly.

Key Features of Hystrix: