Circuit Breaker
Stop repeated calls to a failing dependency and cautiously test recovery.
system design, circuit breaker, resilienceFail fast, then test
A circuit breaker watches calls to a dependency. In closed state it lets calls through; after a configured failure threshold it opens, preventing further calls for a period. In half-open state it permits limited probes. Success can close the circuit; another failure can open it again.
Payment service
- Payment calls time out repeatedly and the configured threshold is reached.
- The breaker opens; new calls fail fast instead of piling up.
- After the wait, a limited probe succeeds and the breaker closes. A timeout does not prove a payment failed: reconcile uncertain outcomes using the provider's transaction identity and idempotency support.
See the reasoning
Trace breaker states
See a dependency fail and a limited recovery probe succeed. This is a prepared demonstration, not live code execution.
Closed
- ClosedCalls allowedCurrent focus
- OpenInactive
- Half-openInactive
Calls flow until the configured failure threshold is reached.
Forecast provider
When a weather provider is unavailable, the app might show a clearly dated cached forecast or an unavailable message. A stale forecast may be unsafe for some decisions, so choose the fallback based on the use case and its maximum acceptable age; do not silently present it as current.
Trade-offs and failure
Thresholds that are too sensitive reject useful traffic; slow thresholds allow more load to pile up. Count relevant failures, set per-call timeouts, monitor state transitions, and limit probes. A breaker does not fix a provider, ensure durable work, or prove that an ambiguous request had no effect.
Reflect on the concept
Four fixed questions to reinforce the reasoning. Answers are not saved or scored.
