DEV Community

Cover image for Circuit Breaker Pattern in 30 seconds
Mirco
Mirco

Posted on • Updated on • Originally published at verbosemode.dev

Circuit Breaker Pattern in 30 seconds

In a microservice architecture, remote services may be unavailable for a long time. Retrying a request won’t help in this case.

The Circuit Breaker pattern offers a solution to this problem.

The CB has three states: closed, half-open, and open.

  • It starts in closed state. Your service executes all calls to the remote service.
  • CB switches to open if many requests fail. Your service starts a timer and does not execute any calls to the service. It returns a default answer or throws an exception instead.
  • CB switches to half-open when the timer is up. Your service executes a fraction of the calls. If all pass, it switches to “closed”. If one fails, it switches to “open” again and restarts the timer.

To summarize, the Circuit Breaker prevents the execution of calls which are doomed to fail. Look here/circuit-breaker) for more information.

Learn four more patterns here!

ko-fi

Top comments (0)