Explain the states of a circuit breaker
“Walk me through Closed, Open and Half-Open. What triggers each transition, and what should the caller do while the breaker is open?”
What this tests
- The three states and the transitions with concrete thresholds
- Why a minimum call count and a window exist
- What "fail fast" returns to the user
- Scope: one breaker per dependency, not one global switch
Answers by level
Read the beginner answer first and notice what is missing.
Closed: calls pass; the breaker counts outcomes over a sliding window (last 100 calls or last 60 s). When the failure rate crosses a threshold (say 50%) and a minimum number of calls has been seen (say 20, so two failures out of two do not trip it), it moves to Open. Open: calls are rejected immediately without touching the dependency, for a fixed duration (10–30 s). Then Half-Open: a small number of probe calls (1–5) are allowed; if they succeed, back to Closed and the counters reset; if any fails, back to Open with a fresh timer.
While open, the caller should not simply throw. It returns a fallback: a cached value, a default (an empty recommendations list), or a clear degraded response ("try again shortly") within milliseconds. The point is to protect the caller's threads and give the dependency room to recover — see Circuit Breaker.
Green flags · Red flags
- Three states with numeric thresholds and a minimum call count
- Half-open as a limited probe, not a full reopen
- Fallback behaviour when open, specific to the feature
- Per-dependency scope
- Counts timeouts and slow calls as failures
- "When the breaker opens we retry until it closes."
- One global breaker for the whole service
- Trips on the first error with no minimum sample
- Cannot say what the caller returns while open