Skip to content
Technology transformation expertise firm · ARDIANE Group Innovate, secure, succeed

Glossary

Circuit breaker: the pattern, its three states and its settings

Domains

Engineering · Cloud and platforms

In brief

The circuit breaker is a software resilience pattern: an object wraps a call to a remote service, counts its failures and, beyond a threshold, immediately returns an error without attempting the call. After a delay, a trial call decides whether to return to normal. Martin Fowler, who describes it in an article dated 6 March 2014, credits Michael Nygard's book "Release It!" with popularising it.

Page contents

A remote call that no longer responds

A call to a remote service can fail, or remain unanswered until a timeout expires. Martin Fowler starts from this observation in his article “Circuit Breaker” (martinfowler.com, 6 March 2014). If many callers wait for a supplier that no longer responds, critical resources can run out, and the failure cascades across several systems. The circuit breaker aims to stop this spread.

Fowler writes that Michael Nygard popularised this pattern in his book “Release It!”. The name borrows the image of a building’s electrical circuit breaker.

Definition of the circuit breaker

The circuit breaker is a design pattern: an object wraps a call to be protected and monitors its failures. When these reach a threshold, the circuit breaker trips: any new call receives an immediate error, and the protected call does not take place. Fowler’s article distinguishes three states, whose names are found in the documentation of libraries such as Resilience4j or Polly.

  1. Closed: calls go through and failures are counted.
  2. Open: calls are rejected without being sent.
  3. Half-open: after a delay, a trial call is allowed through. Its success closes the circuit again, its failure restarts the delay.

This pattern is implemented in code, through a library, or outside the code: the Microsoft Azure architecture documentation mentions service meshes that offer this function, and the microservices.io website associates it with the API gateway.

A textbook case: a show page deprived of its suggestions

Take a ticketing website. A show’s page displays available seats and suggestions provided by a recommendation service. On the evening ticket sales open, this service slows down. Without protection, each page display waits for its response until the maximum timeout, pending requests pile up and sales grind to a halt.

Suppose a circuit breaker set to open after five consecutive failures and to attempt a trial thirty seconds later: these values are pure assumptions, not recommended settings. On the fifth failure, the circuit opens. Pages display immediately, without suggestions, and sales continue. When a trial succeeds, the suggestions return.

Thresholds, delays and fallback: what remains to be decided

The tripping rule is a convention, which varies from one tool to another. Fowler’s example counts failures and resets the counter to zero on the first success; the author also mentions tripping on a failure rate and separate thresholds depending on the type of error. The Resilience4j documentation describes a sliding window, expressed as a number of calls or as a duration, and a threshold on the proportion of slow calls. Fowler points out that not all errors need to trip the circuit breaker: some are part of normal operation.

The pattern has its limits: it does not repair the failing service and does not say what to do when the circuit is open. The caller must provide a fallback. Fowler cites queuing a request for later processing, or displaying older data. He also recommends logging every change of state and letting operations open or close a circuit breaker. These signals feed the monitoring described on our SRE and observability page.

Circuit breaker, timeout, retry, bulkhead: not to be confused

A timeout limits the duration of a call. The circuit breaker relies on it to detect a failure, then avoids waiting for it on every call.

A retry replays a call, betting on a transient fault. The circuit breaker, on the contrary, assumes that the fault persists.

A bulkhead limits the number of simultaneous calls to a dependency. The article “Microservices” by James Lewis and Martin Fowler lists it, along with the timeout, among the other patterns of “Release It!”.

Finally, the circuit breaker is not reserved for one architectural style. Fowler considers it useful wherever one part of a system needs to be protected from the failures of another.

A circuit breaker is set call by call, and the fallback is agreed with the business. This work is part of interface design, covered on our IT architecture page.

FAQ

Frequently asked questions

Another question? Ask us

What is a circuit breaker for?

A circuit breaker protects an application against a remote service that fails or no longer responds. When failures reach a threshold, subsequent calls immediately receive an error, without being sent. The caller stops tying up resources while waiting, and the struggling service is no longer loaded with calls that are bound to fail.

What does the half-open state of a circuit breaker mean?

The half-open state is the state of an open circuit breaker whose timeout has elapsed. A trial call is then allowed through to the protected service. If it succeeds, the circuit closes and calls resume; if it fails, the circuit stays open and the timeout starts again.

Should circuit breaker and retry be combined?

Retry replays a call, counting on a forthcoming success: it suits transient faults. The circuit breaker, on the contrary, prevents a call that is very likely to fail. The documentation of the Polly library advises combining a retry strategy with the circuit breaker where needed, and the Microsoft Azure architecture documentation specifies that retries should stop when the circuit breaker signals a lasting fault.

A project to bring to completion?

A first conversation is enough to understand your challenge, identify the right people and tell you frankly what we can bring.