Design a Circuit Breaker
Design a low-level circuit breaker system for managing API calls to external dependencies, supporting three states (CLOSED, OPEN, HALF_OPEN) with configurable failure thresholds, timeout durations, and automatic state transitions. The system should be thread-safe, provide fallback responses, and expose metrics for monitoring service reliability.
Asked at:
Microsoft
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Mid December, 2025
Microsoft
Senior
Design a low-level Circuit Breaker for a service that makes synchronous API calls to an external dependency. The circuit breaker should support three states: CLOSED, OPEN, and HALF_OPEN. In the CLOSED state, all requests are allowed and failures are counted; if the number of failures crosses a configurable failureThreshold within a sliding time window, the circuit should transition to the OPEN state. In the OPEN state, all incoming requests should be short-circuited immediately and a fallback response should be returned; after a configurable timeoutDuration, the circuit should move to the HALF_OPEN state. In the HALF_OPEN state, only a limited number of test requests should be allowed; if a configurable successThreshold of consecutive successful calls is reached, the circuit should transition back to CLOSED, otherwise any failure should move it back to OPEN. The design should be thread-safe, configurable, and easily integrable with a REST client, and should expose metrics such as failure count, state transitions, and request rejections.
Your account is free and you can post anonymously if you choose.