Question presented to candidate:
"One of our services calls a recommendations API that sometimes becomes slow or starts timing out, and when it does, our own service falls over too. What is the circuit breaker pattern, how does it work, and how would you configure one here?"
What a strong answer should cover:
The problem it solves: calls to a failing dependency tie up threads and connections until timeouts fire, so the caller runs out of resources and the failure cascades
The three states: closed (calls pass, results counted), open (calls fail fast without touching the dependency), half-open (a few trial calls decide whether to close or reopen)
Trip conditions: failure rate (and slow-call rate) over a sliding window, with a minimum number of calls so a single error does not trip it
What the caller does when open: a fallback (cached or default value, degraded feature) or a fast, clear error
How it fits with timeouts, retries with backoff, bulkheads and load shedding; typical tools (Resilience4j, service-mesh outlier detection)
Trade-offs: open-state wait too long delays recovery, too short hammers a sick service; breakers per dependency or per host
Code / implementation expected: Optional โ a small state machine is a plus; the example runs one on a fake clock and counts calls, timeouts and blocked time.
circuit-breaker
2
Try it yourself
Sketch your approach before you read the solution. That is what the interview tests.
Stuck? Get a hint.
A short nudge toward the approach. It will not give the answer away.
3
Solution
Target Audience: Beginners who have called one service from another and want to understand why one slow dependency can take a whole system down, and how a breaker prevents it.
Difficulty: Medium
Verified with: Node 22.22 and Python 3.12 (both print identical output). Library defaults are cited from the Apache Camel Resilience4j configuration reference; the Hystrix status from the Netflix Hystrix README; the pattern history from Martin Fowler's "CircuitBreaker" article (2014).
How to read this doc: Every idea is explained in plain language first, then tagged with ๐ Interview term: so you also learn the words an interviewer expects. Every number comes from running the example; the Verified section quotes its full output.
1. Why This Even Matters โ A Story First
Your house has a fuse box. When a kettle shorts, the breaker for the kitchen trips and the kitchen
The solution is hidden so you can try first
15 min read ยท 12 sections
4
Read the code
Circuit breaker on a fake clock: closed, open, half-open probes, fast-fails and the cost of waiting on timeouts