Low traffic produces misleading failure percentages
Detect: Minimum sample requirements are not met or samples are unrepresentative.
Recover: Tune windows and minimum calls to observed demand.
Stop sending ordinary traffic to an unhealthy dependency, probe recovery deliberately, and protect the rest of the agent workflow from repeated failure.
A circuit breaker observes dependency outcomes and temporarily rejects calls when configured failure or slow-call conditions indicate poor health. Closed permits calls, open rejects them, and half-open allows a limited recovery sample. It is distinct from a timeout, retry policy, rate limiter, or concurrency bulkhead; those controls address different failure dimensions.
Resilience4j provides configurable count-based or time-based sliding windows, minimum call counts, failure and slow-call thresholds, and half-open behavior. Choose failure classification carefully. A user's invalid request should not normally declare the entire dependency unhealthy, and a breaker does not cancel calls already in flight.
A prototype can simulate dependency errors and observe state transitions. Avoid selecting production thresholds from a handful of successful demo calls.
Production tunes windows and minimum samples to actual traffic, scopes breakers by dependency or meaningful failure domain, and defines a useful open-state response.
At scale, too many fine-grained breakers create state and metric cardinality, while one global breaker can spread a localized outage. Test recovery under load and ensure probes do not all arrive simultaneously across instances.
Distinguishes dependency failures and slow calls from expected business rejections.
Tracks the sample used to evaluate configured failure and latency conditions.
Controls closed, open, and limited half-open admission.
Returns cached, partial, queued, or unavailable results according to business policy.
Exposes transitions, rejected calls, sample counts, and recovery behavior.
stateDiagram-v2
[*] --> Closed
Closed --> Open: Minimum sample and failure threshold met
Open --> HalfOpen: Recovery wait completed
HalfOpen --> Closed: Probe outcomes acceptable
HalfOpen --> Open: Probe outcomes unhealthy
Closed --> Closed: Record admitted call outcomes
Open --> Open: Reject ordinary callsSelect the breaker for the dependency and operation's actual failure domain.
Permit normal traffic when closed, reject when open, or allocate a half-open probe.
Apply a separate timeout and concurrency control to the admitted call.
Count configured failures and slow calls while excluding expected business responses.
Open only after the required sample and thresholds are met, then wait according to recovery policy.
Admit limited tests, close after acceptable results, or reopen when the dependency remains unhealthy.
Travel operations · Illustrative enterprise scenario, not a reported customer outcome.
A travel platform's assistant checks hotel inventory while assembling business-trip options.
A slow supplier endpoint causes repeated waits and consumes worker capacity across unrelated itinerary requests.
The assistant must stop overloading the supplier and continue with clearly identified available evidence.
A supplier-scoped breaker records relevant errors and slow calls, while timeouts and bulkheads protect individual requests and worker capacity.
If probes fail, the breaker reopens and the itinerary remains explicit about missing inventory rather than showing stale availability as current.
Track state duration, rejected calls, probe outcomes, and unaffected supplier latency. A breaker improves containment, not the failed dependency itself.
| Decision | Benefit | Cost |
|---|---|---|
| Fast rejection | Workers avoid repeatedly waiting on a known unhealthy service. | Some calls that might have succeeded are rejected. |
| Fine-grained breakers | Local failures have a smaller blast radius. | State and telemetry cardinality increase. |
| Slow-call thresholds | Degradation can be detected before complete failure. | Poor tuning can open the breaker during legitimate long operations. |
Detect: Minimum sample requirements are not met or samples are unrepresentative.
Recover: Tune windows and minimum calls to observed demand.
Detect: Outcome classification counts caller mistakes as dependency failures.
Recover: Exclude expected rejections and retain separate business metrics.
Add a bulkhead or semaphore for in-flight capacity.
Respect the open-state policy and avoid retry amplification.
Scope health to the actual dependency boundary.