Infrastructure · Primitives

CircuitBreaker

Fail-fast protection against cascading failures

Definition

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.

Preconditions

  1. Failure threshold defined
  2. Target resource identified

Postconditions

  1. Internal state updated based on outcome
  2. Request processed OR Blocked

Invariants

  1. Fail Fast: If State == 'OPEN', request MUST be rejected immediately with zero backend cost.
  2. Leakage Protection: In 'HALF-OPEN' state, concurrency is capped (default: 1) to prevent flood during recovery.
  3. State Persistence: Failure counts reset only on successful transition to 'CLOSED'.

Risks

Failure modes

  1. Flapping

    Threshold too sensitive causes circuit to oscillate between Open/Closed.

  2. Zombie {{state}}

    Circuit stuck 'OPEN' because reset logic failed to trigger or persists in failure.

  3. False Positive

    Transient network blips trip circuit, blocking healthy traffic.

Relationships

Builds on

References

Backoff

Delay subsequent attempts after failure or contention

State

System condition at time T

Used by

References

FailClosed

Default-deny policy for uncertain states

Mind

Retry

Classified re-attempt with backoff conditioned on failure type

Mind

StopDrill

Exercise the means of stopping an activity while it runs, so that it still works when needed

Composes with

Society

Rollout

Progressive deployment with canary gating and recorded compensation

Reference

Parameters

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

Identity

Ref
CircuitBreaker#3caa
Sema ID
sema:CircuitBreaker#mh:SHA-256:3caa9c387c04bb2ac66ec35a6cfe2665e11339f0d47576b96d68229226580c76
Ring
1
Tier
1
Updated
2026-11-11
Supersedes
  • sema:CircuitBreaker#mh:SHA-256:41621375faf5609423cb05060fbdccf92c6d8f856607a2ae4bf35a76c90cbaec
  • sema:CircuitBreaker#mh:SHA-256:840fee4c2a300c1e17bd44e55debdf58d250ab62f79760f59c0189ca7d485824