What is a circuit breaker pattern?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex System Design topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
The circuit breaker pattern prevents a cascade of failures in a distributed system by stopping requests to a failing service and allowing it time to recover. Named after electrical circuit breakers that trip to protect circuits from overload. Three states: (1) Closed (normal): requests flow through normally; failures are counted. When failures exceed a threshold within a time window, the circuit "trips" to Open; (2) Open: requests fail immediately without calling the downstream service — fast failure, no waiting for timeouts. After a configured timeout, transitions to Half-Open; (3) Half-Open: allows a limited number of test requests through. If they succeed, circuit Closes (service recovered); if they fail, circuit re-Opens. Why it matters: without circuit breaking, a failing service causes all callers to wait for timeouts (e.g., 30s each), exhausting threads/connections and causing cascade failures. The circuit breaker provides immediate "fail fast" response. Configuration parameters: failure threshold (e.g., 50% of requests fail), time window (measure failures over last 30s), timeout in Open state (try recovering after 60s), success threshold to close (3 consecutive successes in Half-Open). Implementations: Netflix Hystrix (deprecated), resilience4j (Java), opossum (Node.js), Polly (.NET). Combined with: retry (with exponential backoff), timeout, bulkhead, and fallback patterns for comprehensive resilience.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex System Design answers easy to follow.
Previous
What is idempotency and why is it important?
Next
What are the ACID properties in databases?