software-engineering

Definition

Circuit Breaker

The Circuit Breaker is a design pattern used in software development to prohibit repeated (unnecessary) requests to services that are likely to fail.

Example: If my service can’t reach an external services 3x in a row, further requests are disabled by the circuit breaker for the next 5 minutes. After this period, the services tries to request again.

States

The states are similar to the flow of electricity in electric circuits.

Closed

Closed state means that the electricity flows, meaning that API requests are dispatched on demand. No API requests are prohibited.

Open

Open state means that the electricity flow is interrupted, meaning that API requests are prohibited to reduce unnecessary traffic. All API requests are prohibited.

Half-Open

Half-Open means that the system was previously in open state and tries to get back into the closed state. The next API request is a trial-and-error:

  • If the API request is successful the system transitions into the closed state
  • If the API request failed the system transitions back into the open state

Time-Based

Normally, the system is put into open state for a fixed interval (which might increase over time). After that interval, the system transitions into half-open state and tries to transitions back into closed state, meaning operational.