Spring microservices · Concept
How a Resilience4j circuit breaker works
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
Explain how a circuit breaker works in Resilience4j: its states, what makes it open, and what callers get while it's open.
Then
Follow-ups the interviewer asks next
- What's a sliding window: count-based or time-based?
- What's a slow-call threshold, and why does it matter?
- What should the fallback do for a payment call compared with a recommendations call?
- In what order do retry, circuit breaker, time limiter and bulkhead wrap a call?
- How do you see a breaker's state in production?
The answer
What a strong answer covers
- States: CLOSED (calls go through and results are recorded), OPEN (calls fail at once with
CallNotPermittedException), HALF_OPEN (a few trial calls decide whether to close again or reopen). - It opens when the failure rate or the slow-call rate in the sliding window passes a threshold (for example 50%), once
minimumNumberOfCallshave been recorded; it stays open forwaitDurationInOpenState. - Windows: count-based (the last N calls) or time-based (the last N seconds).
- Slow calls count: a dependency that answers in 9 seconds hurts more than one that fails fast.
- Fallbacks: cached or default data for optional things (recommendations); for payments, fail clearly or queue for later. Never pretend a payment succeeded.
- Order with the Resilience4j Spring Boot annotations by default: Retry wraps CircuitBreaker, which wraps RateLimiter, TimeLimiter, Bulkhead and then the call. Each retry attempt is recorded by the breaker; don't retry
CallNotPermittedException. - Visibility: the Actuator
circuitbreakersandcircuitbreakereventsendpoints, Micrometer metrics such asresilience4j_circuitbreaker_state, alerts on state changes. - Spring Cloud Circuit Breaker wraps Resilience4j (2.4.0 in Spring Cloud 2026.0); plain Resilience4j annotations (
@CircuitBreaker(name = "inventory", fallbackMethod = "...")) are just as common.
The red pen
Common traps
Avoid:"a circuit breaker retries for you"; one breaker shared by all downstream services; fallbacks that hide lost data.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.