Email copiado — support@tuurt.com
Cargando experiencia
java · October 28, 2026 · 6 min

Resilience4j in Spring Boot: why the circuit breaker does not open when it should

A properly annotated CircuitBreaker can stay CLOSED while the external provider fails most of its calls. We go through the sliding window, what counts as a failure, and the half-open state.

By Tuurt Team

Resilience4j in Spring Boot: why the circuit breaker doesn't open when it should

Wiring up a CircuitBreaker with Resilience4j feels safer than it actually is. You add the dependency, annotate the method with @CircuitBreaker, set a reasonable-looking failureRateThreshold, and in the local demo -where failures come from a mock that always throws- the breaker opens exactly when it should. The problem shows up in production, with real, intermittent traffic, where the breaker sits in CLOSED for minutes while the external provider is already failing most of its calls, and the service's threads keep draining waiting on those calls. The configuration wasn't written wrong; it was designed for a traffic pattern the service doesn't actually have.

The sliding window doesn't measure what it looks like it measures

Resilience4j evaluates failureRateThreshold over a sliding window, and that window can be COUNT_BASED or TIME_BASED. The trap is that both assume a roughly constant volume of traffic, and most internal services don't have that.

CircuitBreakerConfig config = CircuitBreakerConfig.custom()
    .slidingWindowType(SlidingWindowType.COUNT_BASED)
    .slidingWindowSize(10)
    .minimumNumberOfCalls(10)
    .failureRateThreshold(50)
    .waitDurationInOpenState(Duration.ofSeconds(30))
    .build();

With COUNT_BASED and a size of 10, the breaker needs ten calls before it evaluates the failure rate, no matter how long it takes to collect them. For an endpoint hit every few seconds, that's fast. For a job that runs every five minutes and makes two or three calls to an external provider per run, collecting ten calls can take over an hour, and during that hour the breaker stays closed even if the provider has been down since minute one. The missing piece wasn't a mistyped parameter — it was choosing COUNT_BASED for a traffic pattern that actually needed TIME_BASED, where the window is evaluated by elapsed time instead of accumulated call count.

CircuitBreakerConfig config = CircuitBreakerConfig.custom()
    .slidingWindowType(SlidingWindowType.TIME_BASED)
    .slidingWindowSize(60) // seconds
    .minimumNumberOfCalls(5)
    .failureRateThreshold(50)
    .build();

With this setup, the breaker evaluates the failure rate over the last 60 seconds, as long as at least five calls landed in that window. If the job only makes two or three calls per run and runs are minutes apart, minimumNumberOfCalls set to 5 can still go unmet within the time window, and the breaker never gets to evaluate anything. For sporadic traffic, minimumNumberOfCalls has to be set against how many real calls actually fall inside the window, not against a number that looks reasonable in isolation.

What counts as a failure, and what's being silently ignored

By default, Resilience4j records any Throwable as a failure unless it's explicitly excluded. That sounds exhaustive, but real services usually have an exception-translation layer -an HTTP client that wraps network errors in its own domain exception, a WebClient that turns a 503 into a business exception before it reaches the code that calls the CircuitBreaker- and if that custom exception doesn't inherit from a class Resilience4j is configured to count, the real failure never registers as a failure for the breaker.

CircuitBreakerConfig config = CircuitBreakerConfig.custom()
    .recordExceptions(ExternalProviderException.class, TimeoutException.class)
    .ignoreExceptions(ValidationException.class)
    .build();

recordExceptions works as an allowlist: once declared, only those exceptions -and their subclasses- count as a failure for the breaker, and any other exception that escapes the protected method is ignored for failure-rate purposes, even though it still propagates upward. It's easy to write this list based on the errors seen in development and forget that the real HTTP client wraps connection timeouts in a different exception than the one that shows up in mock-based tests.

There's a second kind of failure that isn't an exception at all: a slow call that does respond, but takes long enough to drain the same thread pool a failed call would. Resilience4j has a separate concept for this, slowCallDurationThreshold and slowCallRateThreshold, which isn't active unless explicitly configured:

CircuitBreakerConfig config = CircuitBreakerConfig.custom()
    .slowCallDurationThreshold(Duration.ofSeconds(2))
    .slowCallRateThreshold(50)
    .build();

Without this, a provider that returns a 200 but takes eight seconds instead of the usual two hundred milliseconds never counts as a failure for the breaker, because technically no exception was thrown. The visible symptom is identical to a provider being down -drained threads, accumulating latency, cascading timeouts upstream- but the breaker sits in CLOSED looking at a failure rate of zero.

The half-open state that flips back to closed before confirming anything

When the breaker moves to OPEN and then to HALF_OPEN, Resilience4j allows a limited number of trial calls before deciding whether to go back to CLOSED or back to OPEN. That number is set with permittedNumberOfCallsInHalfOpenState, and if it's left low -the default is 10, but many configurations lower it to 2 or 3 to minimize the risk of the trial calls themselves- a short lucky streak is enough for the breaker to close again even though the provider is still failing most of the time.

CircuitBreakerConfig config = CircuitBreakerConfig.custom()
    .permittedNumberOfCallsInHalfOpenState(5)
    .waitDurationInOpenState(Duration.ofSeconds(30))
    .automaticTransitionFromOpenToHalfOpenEnabled(true)
    .build();

With automaticTransitionFromOpenToHalfOpenEnabled set to true, the breaker moves to HALF_OPEN automatically after waitDurationInOpenState, without waiting for real traffic. If the external provider happens to have a short window of availability right at that moment -common with providers that fail intermittently rather than completely- the few permitted trial calls can land exactly in that window, close the breaker, and leave it closed until enough real failures pile up to open it again. The breaker isn't badly designed; it's confirming something that needs more evidence with too few samples.

What didn't work the first time

The first time we looked into a breaker that wasn't opening in time, the instinct was to drop failureRateThreshold from 50 to 30, assuming the threshold itself was too high. Nothing changed, because the threshold was never the problem: minimumNumberOfCalls was never being reached inside the configured window, so the breaker never got far enough to evaluate any threshold at all. We confirmed this by exposing Resilience4j's metrics through Micrometer and watching resilience4j_circuitbreaker_calls alongside the breaker's state: the count of calls registered in the window stayed well below minimumNumberOfCalls precisely during the lower-traffic periods — which were exactly the periods where a fast reaction mattered most, since there were fewer successful calls diluting the failed ones.

What we check before trusting a circuit breaker configuration

Before signing off on a CircuitBreaker configuration, we first confirm which window type actually matches the service's real traffic pattern -TIME_BASED for sporadic traffic, COUNT_BASED for steady traffic- and size minimumNumberOfCalls against the real expected volume in that window, not against a number that looks reasonable on its own. We trace the full chain of exceptions the protected call can throw, including whatever an HTTP client or WebClient wraps them in, so recordExceptions isn't silently letting real failures through uncounted. We turn on slowCallDurationThreshold for any call to an external provider, because a slow call that never throws drains the same resources as one that fails outright. And we expose Resilience4j's metrics through Micrometer from day one, because a breaker that isn't reacting is indistinguishable, without those metrics, from a provider that simply hasn't failed yet.

resilience4j spring-boot java microservices
← Back to blog