Sobes.tech
Intern

What is the Circuit Breaker pattern?

sobes.tech AI

Answer from AI

Circuit Breaker is a design pattern used to increase the resilience of distributed systems and prevent cascading failures when interacting with unreliable external services.

The idea is that if an external service starts to frequently return errors or becomes unresponsive, the Circuit Breaker "opens" the circuit and temporarily blocks further requests to that service, returning a predefined response or error. This allows the system to react quickly to problems and not waste resources on repeated failed attempts.

Main states of the Circuit Breaker:

  • Closed: requests pass as usual.
  • Open: requests are blocked, and an error is returned.
  • Half-Open: after a timeout, an attempt is made to send a request to check if the service has recovered.

Example of usage: when calling an external API, if the error rate exceeds a threshold over the last N requests, the Circuit Breaker opens and blocks further calls for some time.