When a downstream payment API slows or errors, naive retries can amplify load and take your service with it. A circuit breaker stops calling the sick dependency for a cooldown window.
Three states
- Closed: traffic flows; failures are counted.
- Open: calls fail immediately (or use fallback); after timeout, transitions to half-open.
- Half-open: a probe request allowed; success closes, failure reopens.
Tune thresholds
Use error rate or consecutive failures sliding windows matching SLOs. Prefer measuring latency percentiles as errors (timeouts).
Not a substitute for retries
Retry with backoff for transient faults; breaker for sustained outages. Combine with bulkheads (thread pools) to isolate failure blast radius.
UX and fallbacks
Return degraded responses or cached data when open; surface clear status to clients.