Reading preferences
Concept

Circuit Breaker

Stop repeated calls to a failing dependency and cautiously test recovery.

system design, circuit breaker, resilience

Fail 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

  1. Payment calls time out repeatedly and the configured threshold is reached.
  2. The breaker opens; new calls fail fast instead of piling up.
  3. 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

Illustrative payment calls
  1. ClosedCalls allowedCurrent focus
  2. OpenInactive
  3. 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.

1. What happens while a circuit is open?
2. Why allow a limited half-open probe?
3. Does a breaker replace a timeout?
4. What should an unknown payment result be treated as?

References and further reading