3-State Circuit Breaker Mechanics & Exponential Backoff Recovery
Retrying a dead upstream on every incoming request wastes latency and amplifies cascading outages. FuelRouter persists an independent 3-state circuit breaker for every upstream in SQLite WAL, isolating failing hosts after 3 consecutive failures and probing recovery safely.
Circuit Breaker State Transition Parameters
| Parameter | Configured Value | Operational Effect |
|---|---|---|
| failure_threshold | 3 consecutive failures | Trips circuit from CLOSED to OPEN; 4th request sends 0 hits to tripped host |
| open_cooldown_s | 45s (ai_chat_json) / 60s (other 4 pools) | Base quarantine duration on first open_trips == 1 |
| backoff_multiplier | 2.0x per failed probe | Escalates cooldown: 60s -> 120s -> 240s -> 480s -> 900s |
| max_cooldown_s | 900s (15 minutes) | Hard upper ceiling so no upstream stays quarantined permanently |
| half_open_probe_limit | 1 concurrent probe | Prevents thundering-herd probe storms upon cooldown expiration |
| recovery_success_threshold | 1 verified HTTP 2xx hit | Resets state to CLOSED, consecutive_failures: 0, open_trips: 0 |
| retry_after_cap_s | 300s (5 minutes) | Honors upstream Retry-After headers without allowing malicious multi-day locks |
Exact Exponential Backoff Equation
Whenever consecutive_failures reaches 3 (or an upstream triggers an enforced 429 / CAPTCHA quarantine), FuelRouter increments open_trips and calculates backoff_s = min(open_cooldown_s * (2.0 ** (open_trips - 1)), 900). If the upstream supplied a Retry-After header, cooldown_s = min(max(backoff_s, retry_after_s), 900).
Until the current Unix timestamp reaches circuit_open_until_ts, every request skips the OPEN upstream completely—zero network sockets opened, zero wasted milliseconds.
Single-Probe HALF_OPEN Gate & Operator Overrides
As soon as now_ts >= circuit_open_until_ts, the next dispatch transitions the upstream to HALF_OPEN and increments half_open_in_flight to 1. Any concurrent threads arriving while that probe is running skip the upstream so a fragile provider is never hammered by parallel probes.
If the single probe passes the Anti-Fake-200 gate, the circuit closes immediately. If it fails, open_trips increments and the circuit re-opens at double the previous cooldown. Operators can also force immediate recovery via POST /v1/router/circuit/reset.
Manually Reset a Tripped Circuit After External Provider Recovery
curl -fsSL -X POST "https://fuelrouter.fastmesh.dev/v1/router/circuit/reset" \
-H "Content-Type: application/json" \
-d '{
"pool_id": "web_search",
"upstream_id": "search_tavily_free"
}'
Circuit Breaker Verification Scenarios
- Three consecutive HTTP 503 responses trip Node A to OPEN; the 4th request routes directly to Node B with 0 hits to Node A.
- After cooldown expires, exactly 1 HALF_OPEN probe executes; success resets state to CLOSED and clears open_trips.
- A failed HALF_OPEN probe doubles the cooldown duration up to max_cooldown_s (900s).
- Resetting via POST /v1/router/circuit/reset restores CLOSED state atomically across all worker threads.
Frequently Asked Technical Questions
Does a 400 or 422 caller validation error trip an upstream's circuit breaker?
No. Client statuses 400 and 422 are classified as non_retryable_client_statuses and never penalize upstream health.
Why limit HALF_OPEN probes to 1 in-flight request?
Under high concurrency, allowing 20 threads to probe simultaneously creates a thundering herd that immediately re-trips a recovering upstream.
Where is circuit breaker state persisted?
All circuit states, open_trips, and unlock timestamps are persisted atomically in SQLite WAL inside the configured --state-dir.
Live Try-Now Console & Machine Discovery
Test failover routing, dry-run quotes, and circuit breaker metrics on the live gateway or connect via JSON-RPC 2.0 MCP.
Related FuelRouter Architecture Guides
- Cloudflare & CAPTCHA Soft-Ban Failover Without Anti-Bot Bypass — Cloudflare Turnstile CAPTCHA soft-ban API failover without bypass
- MCP JSON-RPC 2.0 Failover Router Integration Guide — MCP JSON-RPC 2.0 multi-upstream failover router
- SSRF Protection & Cloud Metadata IP Blocking in API Gateways — SSRF protection cloud metadata IP blocking API gateway