diagram.mmd — flowchart
Circuit Breaker Architecture flowchart diagram

The circuit breaker pattern prevents a service from repeatedly attempting calls to a failing downstream dependency, allowing the dependency time to recover while failing fast to callers — similar to how an electrical circuit breaker stops current flow to prevent damage.

What the diagram shows

The diagram models the three states of a circuit breaker as a state machine. In the Closed state, requests flow normally from the calling service through the circuit breaker to the downstream service. The breaker tracks the failure rate; if it exceeds a configured threshold (e.g. 50% of the last 10 calls), the breaker trips and transitions to Open.

In the Open state, no requests are forwarded to the downstream service — the breaker returns an error immediately to the caller, preventing latency buildup and thread pool exhaustion. After a configured timeout (e.g. 30 seconds), the breaker transitions to Half-Open and allows a single probe request through. If the probe succeeds, the breaker resets to Closed; if it fails, the breaker returns to Open and resets the timeout.

Why this matters

Without a circuit breaker, a slow or failing downstream service causes the calling service's thread pool to fill with waiting connections, eventually cascading the failure to all callers — a distributed system equivalent of a stack overflow. The circuit breaker breaks that cascade by failing fast. It is a core resilience primitive in microservice architectures. For the broader resilience architecture, see High Availability System. For the retry logic that works alongside circuit breakers, see Request Retry Logic.

Free online editor
Edit this diagram in Graphlet
Fork, modify, and export to SVG or PNG. No sign-up required.
Open in Graphlet →

Frequently asked questions

The circuit breaker pattern is a resilience mechanism that monitors calls to a downstream dependency and, when failures exceed a threshold, stops forwarding requests and returns errors immediately — giving the dependency time to recover while preventing cascading failures.
The breaker has three states: Closed (requests flow normally, failures are counted), Open (requests fail fast without touching the downstream service), and Half-Open (a single probe request is allowed through to test recovery). Success in Half-Open resets to Closed; failure returns to Open.
Use a circuit breaker on any synchronous call to an external service or database that could become slow or unavailable. It is especially important in microservice architectures where a single failing downstream dependency can exhaust the thread pool of every upstream caller.
Common mistakes include setting the failure threshold too low (causing false trips under normal traffic spikes), setting the timeout too long (leaving the breaker Open longer than necessary), and not providing a meaningful fallback response when the breaker is Open.
mermaid
flowchart TD Caller[Calling Service] --> CB{Circuit Breaker\nState?} CB -->|Closed| Forward[Forward Request\nto Downstream Service] Forward --> Result{Request\nResult} Result -->|Success| CountSuccess[Record Success\nReset failure count] Result -->|Failure| CountFail[Record Failure\nIncrement counter] CountFail --> Threshold{Failure rate\nexceeds threshold?} Threshold -->|No| CB Threshold -->|Yes| TripOpen[Trip to OPEN state] CB -->|Open| FastFail[Return Error\nImmediately - No call made] FastFail --> WaitTimeout[Wait recovery\ntimeout - 30s] WaitTimeout --> HalfOpen[Transition to\nHALF-OPEN state] CB -->|Half-Open| ProbeRequest[Send single\nprobe request] ProbeRequest --> ProbeResult{Probe\nResult} ProbeResult -->|Success| Reset[Reset to CLOSED\nstate] ProbeResult -->|Failure| TripOpen
Copied to clipboard