# Circuit Breaker

A resilience pattern that temporarily rejects calls to an unhealthy dependency and later probes for recovery.

- Type: framework
- Domain: Engineering & architecture
- Level: Intermediate
- Last reviewed: 2026-09-24
- Original: [Soroush’s Product Wiki](<https://wiki.soroush.uk/topic/circuit-breaker/>)

## What it means

A circuit breaker wraps calls to a dependency and changes behavior according to recent outcomes. In the closed state calls flow normally; after a failure threshold it opens and fails calls quickly; after a pause it becomes half-open and permits limited probes before closing or reopening. It differs from retry because it suppresses attempts unlikely to succeed.

## Why it matters

Repeated calls to a slow or failing dependency tie up resources and spread failure through a product. A breaker limits that pressure, shortens predictable failures, and creates a controlled point for fallback or degradation while the dependency recovers.

## When to use it

Use a circuit breaker around remote dependencies with failures that can persist and where fast rejection or fallback is safer than continued waiting. It is usually unnecessary for local deterministic errors, and it cannot replace timeouts, capacity planning, exception handling, or recovery of the dependency itself.

## How it works

1. Define which failures and latency outcomes indicate dependency health.
2. Allow calls while closed and track outcomes over a suitable rolling window.
3. Open the circuit when the configured threshold is exceeded and reject calls quickly.
4. Provide a bounded fallback or clear degraded state where the product can do so safely.
5. After a recovery interval, allow limited half-open probes.
6. Close on demonstrated recovery or reopen on failure, while exposing state and metrics.

## A practical example

A travel search service sees sustained timeouts from a recommendation provider. Its circuit opens, search continues without personalized rankings, and only a few probes are allowed after the recovery interval. Normal ranking resumes after the probes succeed.

## Where it breaks

Thresholds that are too sensitive cause needless degradation; slow thresholds allow cascading failure. Breaker state can differ across instances, and a fallback may be stale or unsafe. The pattern rejects work but does not repair the dependency or preserve every request.

## Common mistakes

- Confusing a circuit breaker with retry and continuing to call while it is open.
- Counting expected business rejections as dependency failures.
- Using a fallback that hides incorrect or dangerously stale data.
- Operating the breaker without visible state, metrics, or recovery testing.

## Visualization

[View the visualization on the website](<https://wiki.soroush.uk/topic/circuit-breaker/#visualization-circuit-breaker>)

## Sources

1. [Circuit Breaker Pattern](<https://learn.microsoft.com/en-us/azure/architecture/patterns/circuit-breaker>) — Microsoft Learn · Institutional architecture guide
2. [Circuit Breaker](<https://martinfowler.com/bliki/CircuitBreaker.html>) — Martin Fowler · Authoritative technical article

## Related topics

- [Retry](<https://wiki.soroush.uk/topic/retry/>)
- [Timeout](<https://wiki.soroush.uk/topic/timeout/>)
- [Incident Management](<https://wiki.soroush.uk/topic/incident-management/>)
