Skip to content
Engineer
Menu
Design
English

Engineer / Glossary

Circuit breaker

a guard that pauses calls to an unhealthy dependency

What it is

A circuit breaker remembers how calls to a dependency have been going and decides whether to send another. Consider a service that calls a remote inventory system. When the inventory system becomes slow or unavailable, a breaker can temporarily stop forwarding calls to it. Requests that would have used the missing service receive an immediate outcome determined by the caller’s contract. The protected service avoids holding every waiting request until its timeout, and the dependency gets some space to recover.

The common pattern has three states. A closed breaker allows ordinary calls and collects outcomes. When enough qualifying failures or slow calls appear in the measurement window, it opens. An open breaker declines calls according to its policy. After a wait or a separate recovery signal, a half-open breaker admits a bounded set of probes. The results of the probes determine whether it closes and restores service or opens again. The thresholds and observation rules belong to the implementation. An application library such as Resilience4j describes a state machine with these three usual states and several explicit administrative states. Envoy applies network-level resource limits under its circuit breaking feature, so its knobs answer a related admission question with different details.

Engineers often combine a breaker with a per-request timeout, a retry budget and a concurrency limit. A timeout limits the time one caller waits. A retry policy decides whether one failed operation may be attempted again. A concurrency limit caps the count of work in flight. A breaker changes the decision for later callers based on earlier outcomes. State the role of each before choosing defaults, particularly if multiple libraries or proxies already apply their own limits.

Why it matters

Unhealthy dependencies can turn one slow path into a system-wide error. When hundreds of waiting requests occupy workers or database connections, even the routes that would have succeeded may be unable to run. A fast rejection keeps those resources available for requests the service can still answer. The biggest gain is often including failure as an expected path in the design rather than hoping a dependency returns quickly under exceptional conditions.

Applying this logic correctly depends on what the user sees. A delayed image preview may be replaced by its last completed version if the product permits that. A shipping reservation should not silently succeed when the reservation system refuses the call. An accurate response distinguishes unavailable, temporarily delayed and verified successful work, and gives a separate action for each outcome. Operators need to know what fallback and recovery mean in the affected workflow. A dashboard that shows all fast responses may hide a system returning degraded results at high volume.

A breaker also protects recovery. When a failing service comes back and every client immediately retries, the rebound can trigger another outage. A small half-open allowance and controlled retries limit the recovery load. If clients do this independently, their probes can still land together. Teams may spread retry times or use a shared concurrency policy when an upstream dependency cannot take a simultaneous burst from many callers.

What it looks like in practice

Imagine an online catalogue that reads product information and current inventory from separate services. Customers may still browse current product descriptions when the inventory service is unavailable. The catalogue displays an explicit availability message and keeps the purchase action dependent on a verified inventory reservation. The failure decision for catalogue enrichment can therefore differ from the decision for an actual purchase. One breaker per dependency and operation class gives the service a way to express that split. A single breaker for the entire website would close off useful routes along with the failing work.

A test starts with a healthy dependency and then introduces increasing latency. Measure how many calls are admitted and how long requests retain server resources. Confirm that a timeout contributes to the chosen failure category and that validation errors returned to a caller do not open the breaker. Once open, observe the application response and verify the monitored cause. Bring the dependency back in steps. Inspect what happens when the first probe succeeds but the next fails, as intermittent recovery is different from a clean restart. Prove that normal traffic resumes without restarting the catalogue or clearing all metrics.

Run the same test with several service instances. The window and half-open state may be per process, so one instance can recover while another stays open. An operator needs to recognise that pattern in telemetry, rather than assuming one open-state metric describes the whole fleet. Record outcomes for attempted, rejected and successfully degraded work as distinct facts.

The case study on building the company’s first observability dashboard describes bringing operational signals together so that the people running the system can follow what changed. The catalogue scenario is illustrative. The relevant connection is making the state and the affected behaviour visible side by side. A breaker state is useful in diagnosis when the operator can connect it to changes in dependency latency and to requests that could still be served.

Where it goes wrong

A breaker opens on caller mistakes because the implementation counts every failed response together. A malformed input or a missing required field offers little evidence that the remote system is unhealthy. Classify failures by what action should follow. Read the upstream API’s error contract so expected errors are measured at their own boundary, and keep representative tests for each class.

A very short window amplifies noise. After two requests, a single failure is half the sample even though the service might be healthy. Establish a minimum observation count before opening on a rate, and consider explicit signals for exceptional cases where one response is meaningful. Bigger windows smooth transient noise but take longer to notice recovery and genuine deterioration. Measure both directions under realistic traffic, including quieter periods.

Fallback work can exceed the capacity saved by opening. A caller that replaces one failing lookup with several slower searches reintroduces the same resource pressure through a different path. Keep the degraded response small, put it under a separate budget if it uses another dependency, and monitor how often customers receive it. Administrative overrides should have an owner and an expiry. Otherwise an emergency circuit state can become an unnoticed permanent configuration change.

Further reading

Contact

Still working out what you need?

Tell us what is going wrong, or what you are trying to build. We will tell you what it would take, roughly what it would cost, and whether we are the right people for it.

From 1,400 DKK an hour, excluding VAT — and less per hour on a longer booking.

welcome@engineer.company +45 50 10 61 84 Copenhagen, Denmark