---
title: "Stop calling a failing service with a · Agent Wranglers"
url: https://agentwranglers.se/playbook/operations/capacity-and-resilience/circuit-breakers
id: OPS-74
level: Recommended
updated: 2026-10-27
build: a2a6bdfed830
tokens: 1330
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Stop calling a failing service with a circuit breaker

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Capacity and resilience](https://agentwranglers.se/playbook/operations/capacity-and-resilience.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: OPS-74
- Level: Recommended
- Chapter: [Capacity and resilience](https://agentwranglers.se/playbook/operations/capacity-and-resilience.md)
- Rule: Wrap each call to another service in a circuit breaker. After a set share of failures it opens and fails at once for a pause, such as 30 seconds. Then it lets trial calls through before it closes.
- Check: Block one dependency on staging. Within 30 seconds, calls to it fail in under 10 ms with no network traffic, the fallback answers, and the metric shows the breaker open. Unblock it. The breaker closes within one pause plus the trial calls.
- How: Without a breaker, every request waits its full timeout on a service that is down, and the waiting requests fill the workers. A breaker has three states. Closed passes calls and counts failures. Open fails at once without a network call. Half-open lets a few trial calls through and closes again when they succeed. Open it on a failure rate over enough calls, such as 50% of at least 20 calls. Then two errors at night do not trip it. When it is open, take the fallback chosen in [Decide what happens when a provider is down](https://agentwranglers.se/playbook/api-design/using-other-companies-apis/provider-outages.md). Libraries exist for most languages, such as opossum for Node.js, pybreaker for Python, Resilience4j for Java and Polly for .NET. Report each breaker's state as a metric, and alert when one stays open for 5 minutes. The breaker stops calls to one service. [Cap retries across the whole service](https://agentwranglers.se/playbook/operations/capacity-and-resilience/retry-budget.md) limits retries. [Turn work away before overload](https://agentwranglers.se/playbook/operations/capacity-and-resilience/load-shedding.md) protects your own service. [Keep the app working when the cache is gone](https://agentwranglers.se/playbook/scaling/caching/survive-cache-loss.md) covers the cache.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
import CircuitBreaker from 'opossum';

const shippingBreaker = new CircuitBreaker(fetchShippingRates, {
  timeout: 3000,
  errorThresholdPercentage: 50,
  volumeThreshold: 20,
  resetTimeout: 30_000,
});
shippingBreaker.fallback(order => cachedShippingRates(order));
shippingBreaker.on('open', () => breakerOpen.set({ dependency: 'shipping' }, 1));
shippingBreaker.on('close', () => breakerOpen.set({ dependency: 'shipping' }, 0));

export const shippingRates = order => shippingBreaker.fire(order);
```

### Python example

```python
import pybreaker

shipping_breaker = pybreaker.CircuitBreaker(fail_max=5, reset_timeout=30, name="shipping")


def shipping_rates(order):
    try:
        return shipping_breaker.call(fetch_shipping_rates, order)
    except pybreaker.CircuitBreakerError:
        return cached_shipping_rates(order)
```

## Sources

- [AWS Prescriptive Guidance, Circuit breaker pattern](https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/circuit-breaker.html)

## Related rules

- ARC-90 [Give each outside dependency its own pool](https://agentwranglers.se/playbook/architecture/system-architecture/bulkheads.md) in Clean code and architecture
- OPS-84 [Watch the status of the services you depend on](https://agentwranglers.se/playbook/operations/alerts-and-on-call/dependency-status.md) in Operations and observability
- API-78 [Decide what happens when a provider is down](https://agentwranglers.se/playbook/api-design/using-other-companies-apis/provider-outages.md) in API design
- OPS-66 [Cap retries across the whole service](https://agentwranglers.se/playbook/operations/capacity-and-resilience/retry-budget.md) in Operations and observability
- OPS-40 [Turn work away before overload](https://agentwranglers.se/playbook/operations/capacity-and-resilience/load-shedding.md) in Operations and observability
- SCL-15 [Keep the app working when the cache is gone](https://agentwranglers.se/playbook/scaling/caching/survive-cache-loss.md) in Scaling

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/operations/capacity-and-resilience/circuit-breakers">Agent Wranglers operations and observability playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Cap retries across the whole service](https://agentwranglers.se/playbook/operations/capacity-and-resilience/retry-budget.md)
- Next: [Size the runtime's memory to the box](https://agentwranglers.se/playbook/operations/capacity-and-resilience/runtime-memory-limits.md)
- [Capacity and resilience](https://agentwranglers.se/playbook/operations/capacity-and-resilience.md)
