Jump to content

Circuit breaker design pattern

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Azarboon (talk | contribs) at 12:01, 11 December 2024 (Removed uncited content. Made the tone more neutral). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Circuit breaker is a design pattern used in software development. Circuit breaker pattern can prevent cascading failures particularly in distributed systems.[1]

The circuit breaker pattern can be used in conjunction with other patterns, such as retry, fallback, and timeout, to enhance fault tolerance in systems. [2]

Challenges

According to Marc Brooker, circuit breakers can misinterpret a partial failure as total system failure and inadvertently bring down the entire system. In particular, sharded systems and cell-based architectures are vulnerable to this issue. A workaround is that the server indicates to the client which specific part is overloaded and the client uses a corresponding mini circuit breaker. However, this workaround can be complex and expensive.[3][4]

Different states of circuit breaker

  • Closed
  • Open
  • Half-open

Closed state

When everything is normal, the circuit breakers remained closed, and all the request passes through to the services as shown below. If the number of failures increases beyond the threshold, the circuit breaker trips and goes into an open state.

Circuit Breaker Closed State

Open state

In this state circuit breaker returns an error immediately without even invoking the services. The Circuit breakers move into the half-open state after a timeout period elapses. Usually, it will have a monitoring system where the timeout will be specified.

Circuit Breaker Open State

Half-open state

In this state, the circuit breaker allows a limited number of requests from the service to pass through and invoke the operation. If the requests are successful, then the circuit breaker will go to the closed state. However, if the requests continue to fail, then it goes back to Open state.

Circuit Breaker Half Open State

References

  1. ^ Machine Learning in Microservices Productionizing Microservices Architecture for Machine Learning Solutions. Packt Publishing. 2023. ISBN 9781804612149.
  2. ^ Kubernetes Native Microservices with Quarkus and MicroProfile. Manning. 2022. ISBN 9781638357155.
  3. ^ Understanding Distributed Systems. ISBN 9781838430214.
  4. ^ "Will circuit breakers solve my problems?".