Mid-level interview question
What does a circuit breaker do?
Model answer
Counts failures on a call; past a threshold it opens, failing fast or going straight to the fallback with no timeout wait. After a cool-down it lets one trial through; success closes it.
Scroll sideways to see the whole diagram
Martin Fowler's circuit breaker wraps a remote call and counts its failures.
Text version
- Martin Fowler's circuit breaker wraps a remote call and counts its failures.
- When failures reach a threshold, it trips: further calls return an error immediately, without reaching the failing service, so a fallback can answer at once.
- After a timeout, it lets one trial call through to see whether the problem is fixed.
- If the trial succeeds, the breaker resets; if not, it opens again.
- Fowler's reasons: without it, callers tie up resources waiting on timeouts, failures cascade across systems, and the struggling service keeps getting hit.
In the course's example, users wait 80 s in total instead of 1,000 s during an outage.
Practise the rest
6 Fallbacks questions, 492 in all, each with a model answer. Free.
More Fallbacks interview questions
- What is graceful degradation?
- Your primary is 99% available and a fallback 99.5%. What's combined availability?
- Demand is twice capacity. Why shed load instead of queueing everything?
- You fall back to a model you've never evaluated with your prompt. What can go wrong?
- Retry after a bad output, or send two requests in parallel?