CircuitBreaker
Fail-fast protection against cascading failures
Mechanism
State 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 and retry logic to schedule recovery probes.
Invariants
- Fail Fast: If State == '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 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: 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
Used by
- Exception references
- FailClosed references
- Retry references
- Rollout composes_with
- StopDrill references
Related
Identity
- Ref:
CircuitBreaker#3caa - Hash: sema:CircuitBreaker#mh:SHA-256:3caa9c387c04bb2ac66ec35a6cfe2665e11339f0d47576b96d68229226580c76
- Library: bootstrap 0.11.0, root a6a3d1ff0f98
- License: Not stated; check the repository