Home/Agentic AI/Error Recovery/Circuit Breakers

Error Recovery Strategies

Build resilient agentic systems that gracefully handle failures and recover intelligently

Circuit Breaker Pattern

When a service starts failing, retrying every request makes the problem worse. The circuit breaker pattern stops sending requests to failing services, giving them time to recover while preventing cascading failures.

How Circuit Breakers Work

Think of it like an electrical circuit breaker in your home. When too much current flows, the breaker trips to prevent damage. In software, when too many errors occur, the circuit "opens" to prevent overwhelming a failing service.

Three Circuit States

🟢
Closed (Normal)

Requests flow through normally. Circuit monitors for failures.

Behavior: All requests attempted. Track success/failure rate.
Transition: Opens if failure rate exceeds threshold (e.g., 50% failures in last 10 requests).
🔴
Open (Blocking)

All requests fail immediately without attempting. Protects failing service.

Behavior: Reject all requests instantly. Return cached data or error.
Transition: After timeout period (e.g., 30s), transition to Half-Open to test recovery.
🟡
Half-Open (Testing)

Allow limited requests to test if service has recovered.

Behavior: Allow a few test requests through (e.g., 1-3).
Transition: If tests succeed → Close circuit. If tests fail → Reopen circuit.

Interactive: Circuit Breaker Simulator

Simulate successful and failed requests to see how the circuit breaker responds:

Circuit opens when error rate exceeds this threshold (after 5+ requests)

Circuit Status

CLOSED
🟢

All requests pass through normally. System is healthy.

Total Requests
0
Successful
0
Failed
0
Error Rate
0%
💡
When to Use Circuit Breakers

Use circuit breakers for external service calls (APIs, databases, third-party services). Don't use them for internal function calls or operations that should always succeed. The goal is to prevent cascading failures, not to hide bugs.

← Previous: Retry Strategies