Spring / Resilience4j Interview questions
Explain the lifecycle of a CircuitBreaker instance?
A CircuitBreaker instance is created by name from a CircuitBreakerRegistry - either the default shared registry or one built from custom CircuitBreakerConfig - and it starts in the CLOSED state with an empty sliding window.
As calls flow through it, each outcome (success, failure, or slow call) is recorded into the window; once minimumNumberOfCalls is satisfied, every new call re-evaluates the failure and slow-call rate against their thresholds.
Crossing a threshold moves it to OPEN, where it stays for waitDurationInOpenState before automatically (if enabled) or explicitly moving to HALF_OPEN to run a limited batch of trial calls.
Those trial calls decide the next move: enough successes return it to CLOSED with a fresh window, while failures send it back to OPEN and restart the wait timer - and this whole CLOSED→OPEN→HALF_OPEN cycle can repeat indefinitely for as long as the instance and its dependency both exist.
Throughout, the instance can also be pulled out of this automatic cycle at any time via manual transitionToForcedOpenState(), transitionToDisabledState(), or similar calls, useful for maintenance windows or manual incident response.
More Related questions...