---
library: "bootstrap"
slug: "CircuitBreaker"
name: "CircuitBreaker"
ref: "CircuitBreaker#3caa"
hash: "sema:CircuitBreaker#mh:SHA-256:3caa9c387c04bb2ac66ec35a6cfe2665e11339f0d47576b96d68229226580c76"
type: "Primitives"
layer: "Infrastructure"
version: "0.11.0"
root: "a6a3d1ff0f982ee30430c5b42f3784c8ec901fd68482cfc1bc30899c1e5e48c5"
license: null
url: "https://semahash.org/vocabularies/bootstrap/patterns/CircuitBreaker"
---

# CircuitBreaker

Fail-fast protection against cascading failures

Infrastructure · Primitives

## Mechanism

[State](https://semahash.org/vocabularies/bootstrap/patterns/State.md) machine wrapper for fallible operations. Monitors failure rates of a target resource. States: (1) 'CLOSED': Requests pass normally. (2) 'OPEN': Requests fail immediately (Fail Fast) without invoking target. (3) 'HALF-OPEN': Limited trial requests allowed to test recovery. Transitions: 'CLOSED' -> 'OPEN' if failure count > threshold. 'OPEN' -> 'HALF-OPEN' after reset timeout. It wraps operations, switching to an open state on failure to prevent cascading overloads, while using [Backoff](https://semahash.org/vocabularies/bootstrap/patterns/Backoff.md) and retry logic to schedule recovery probes.

## Invariants

- Fail Fast: If [State](https://semahash.org/vocabularies/bootstrap/patterns/State.md) == 'OPEN', request MUST be rejected immediately with zero backend cost.
- Leakage Protection: In 'HALF-OPEN' state, concurrency is capped (default: 1) to prevent flood during recovery.
- [State](https://semahash.org/vocabularies/bootstrap/patterns/State.md) Persistence: Failure counts reset only on successful transition to 'CLOSED'.

## Parameters

- failure_threshold: type=Integer, range=[1, 100], description=Default: 5
- half_open_limit: type=Integer, range=[1, 10], description=Max probes allowed in half-open state
- reset_timeout: type=Duration, range=unspecified, description=Default: 60s

## Preconditions

- Failure threshold defined
- Target resource identified

## Postconditions

- Internal state updated based on outcome
- Request processed OR Blocked

## Failure modes

- Flapping: Threshold too sensitive causes circuit to oscillate between Open/Closed.
- Zombie [State](https://semahash.org/vocabularies/bootstrap/patterns/State.md): Circuit stuck 'OPEN' because reset logic failed to trigger or persists in failure.
- False Positive: Transient network blips trip circuit, blocking healthy traffic.

## Where this came from

—

## Builds on

- [Backoff](https://semahash.org/vocabularies/bootstrap/patterns/Backoff.md) (references)
- [State](https://semahash.org/vocabularies/bootstrap/patterns/State.md) (references)

## Used by

- [Exception](https://semahash.org/vocabularies/bootstrap/patterns/Exception.md) (references)
- [FailClosed](https://semahash.org/vocabularies/bootstrap/patterns/FailClosed.md) (references)
- [Retry](https://semahash.org/vocabularies/bootstrap/patterns/Retry.md) (references)
- [Rollout](https://semahash.org/vocabularies/bootstrap/patterns/Rollout.md) (composes_with)
- [StopDrill](https://semahash.org/vocabularies/bootstrap/patterns/StopDrill.md) (references)

## Related

- [StopDrill](https://semahash.org/vocabularies/bootstrap/patterns/StopDrill.md)

## Identity

- Library: bootstrap 0.11.0 (root a6a3d1ff0f98)
- Ref: CircuitBreaker#3caa
- Hash: sema:CircuitBreaker#mh:SHA-256:3caa9c387c04bb2ac66ec35a6cfe2665e11339f0d47576b96d68229226580c76

## Links

- Page: https://semahash.org/vocabularies/bootstrap/patterns/CircuitBreaker
- JSON: https://semahash.org/vocabularies/bootstrap/patterns/CircuitBreaker.json
- Library: https://semahash.org/vocabularies/bootstrap
- Library index: https://semahash.org/vocabularies/bootstrap/index.json
