Circuit breaker
Stop spending calls on a dependency that is failing.
The problem and the pattern
A breaker opens after a configured failure threshold and rejects calls for a recovery window. A small half-open probe tests whether the dependency has recovered. This protects latency and capacity; it does not repair the dependency or replace timeouts.
Follow the flow
Make it concrete
This excerpt isolates the concept. Connect it to the booking API as you work through the exercise.
Closed: allow calls and observe failures
Open: fail fast for a recovery window
Half-open: allow a bounded probe
Healthy probe → close; failed probe → reopenTrade-offs
- Fast failure preserves resources during an outage.
- Thresholds need workload evidence to avoid oscillation.
- Provide a useful error and observable state instead of hiding the outage.
When to avoid it
Avoid adding a breaker to local operations with no independent failure boundary.
Your turn
Which failures should trip a payment-service breaker: a timeout or an invalid card request?
Reveal a worked answer
A dependency timeout can indicate unavailability; a client validation error usually should not count as dependency failure. Choose metrics and thresholds for the actual operation, and test recovery rather than only opening.