Scrivio Interview library
InternalsIntermediate6 min read · updated 12 November 2026

When several Resilience4j annotations are on one method (@Retry, @CircuitBreaker, @RateLimiter, @TimeLimiter, @Bulkhead), in what order are they applied by default in Spring Boot, and why does it matter?

By default, Spring Boot's Resilience4j aspects nest as Retry ( CircuitBreaker ( RateLimiter ( TimeLimiter ( Bulkhead ( function ) ) ) ) ), so Retry is the outermost layer and every retry attempt passes through the circuit breaker and is counted by it. That is usually what we want, but it means that once the breaker opens, each attempt gets CallNotPermittedException, so Retry should be configured to ignore that exception or it retries pointlessly. The order can be changed with the aspect order properties, and @TimeLimiter only works on asynchronous return types such as CompletableFuture or reactive types.

Why this question is asked

Stacking five annotations on one method looks like declaring five independent protections, but they are layers wrapped around each other, and the order changes what each layer sees. Does the circuit breaker count one failure or three? Does the rate limiter spend one permit or three? Does the bulkhead hold a slot while Retry sleeps? Interviewers ask this to check that we understand the nesting rather than just the annotations. In this answer, we will recap how aspects wrap a method, follow one call through the default order, look at the consequences for each pair of layers, fix the open breaker retry problem, and see how to change the order and when @TimeLimiter applies.

1A Quick Recap: Annotations Become Nested Wrappers

Each Resilience4j annotation is implemented by a Spring AOP aspect, a piece of code that runs around the method call. When several aspects apply to one method, Spring nests them like Russian dolls: the outermost one runs first on the way in and last on the way out, and it sees whatever the inner ones return or throw. The nesting order comes from each aspect's order value, which Resilience4j sets by default and lets us change through properties.

So the question is never just which protections we have, but which one wraps which.

2The Default Order, Followed Through One Call

The documented default order is Retry ( CircuitBreaker ( RateLimiter ( TimeLimiter ( Bulkhead ( function ) ) ) ) ). Let us follow a call to an inventory method with all five annotations where the first attempt times out and the second succeeds.

Java
@Retry(name = "inventory")
@CircuitBreaker(name = "inventory")
@RateLimiter(name = "inventory")
@TimeLimiter(name = "inventory")
@Bulkhead(name = "inventory")
public CompletableFuture<Stock> stock(String sku) { ... }
// attempt 1: Retry -> CircuitBreaker (closed) -> RateLimiter (permit 1) -> TimeLimiter -> Bulkhead -> call
// call exceeds the time limit -> TimeoutException
// CircuitBreaker records 1 failure; Retry waits 200 ms
// attempt 2: Retry -> CircuitBreaker -> RateLimiter (permit 2) -> TimeLimiter -> Bulkhead -> call -> Stock
// CircuitBreaker records 1 success; result returned
Step throughDefault Resilience4j aspect nesting
  1. Retryoutermost: repeats everything inside it
  2. CircuitBreakerrecords each attempt, may reject with CallNotPermittedException
  3. RateLimitertakes a permit per attempt
  4. TimeLimiterlimits each attempt's duration
  5. Bulkheadholds a concurrency slot only during the call
  6. Your methodthe actual remote call

6 layers, from the top down. Step through them one at a time.

Notice what each layer saw. The circuit breaker saw two calls, one failure and one success, because Retry sits outside it. The rate limiter gave out two permits. The bulkhead was occupied only while each attempt ran, not during Retry's wait, because the bulkhead is inside Retry.

3Why the Order Matters for Each Layer

With Retry outside the circuit breaker, each attempt is a separate outcome in the breaker's window. That is generally right, because the breaker should know about every call that reached the failing dependency. If the order were reversed, the breaker would see one outcome per logical call after all retries, so three timeouts would count as a single failure and the breaker would open more slowly.

With Retry outside the rate limiter, each retry spends a permit, so retries cannot sneak past the limit we agreed with the dependency. With the time limiter inside Retry, the timeout applies to each attempt, not to the whole sequence, so three attempts of 1 second each can take over 3 seconds in total plus waits. That is worth remembering when we set our caller's timeout. With the bulkhead innermost, a slot is held only while a call is actually in flight.

4The Open Breaker Problem and Its Fix

There is a catch in the default order. When the breaker is open, it rejects every attempt immediately with CallNotPermittedException. Retry, sitting outside, sees an exception and, unless told otherwise, retries it: it waits, asks again, is rejected again, and waits again. The user waits for all the backoff delays and gets the same failure at the end, and we have spent time for nothing.

YAML
resilience4j:
retry:
instances:
inventory:
max-attempts: 3
wait-duration: 200ms
ignore-exceptions:
- io.github.resilience4j.circuitbreaker.CallNotPermittedException
// breaker OPEN -> attempt 1 rejected -> not retried -> fallback or error in about 1 ms

With the exception ignored, an open breaker fails fast through Retry as intended, and a fallback, if declared, can serve cached data at once. Similarly, if we retry on all exceptions, RequestNotPermitted from the rate limiter and BulkheadFullException from the bulkhead deserve a decision: retrying them after a backoff may be fine, but retrying them instantly is not.

5Changing the Order

If we need a different nesting, for example the circuit breaker outside Retry, the aspect order properties change it: resilience4j.retry.retry-aspect-order, resilience4j.circuitbreaker.circuit-breaker-aspect-order, and the same pattern for rate limiter, time limiter and bulkhead. Spring decides nesting from these values, so the property names, the default numbers and which direction makes an aspect outermost are worth checking in the documentation for your version, and then confirming with a test that counts breaker calls during a retried failure.

When the order really matters to the design, many teams prefer the programmatic Decorators API, where the order is written explicitly in code and does not depend on aspect configuration.

6@TimeLimiter Needs an Asynchronous Return Type

The time limiter works by waiting on a future with a timeout. It therefore applies only to methods that return CompletableFuture, CompletionStage or a reactive type such as Mono or Flux. On a method that returns a plain value, the call has already finished, or blocked, by the time an aspect could start a timer, so the time limiter cannot interrupt it; check your version for how it reacts.

Also note that when the time limiter fires on a CompletableFuture, it stops waiting, but the underlying work may keep running unless cancellation is enabled and the work responds to it. For a plain synchronous call, the right tool is the HTTP client's own read timeout, which the circuit breaker then records as a failure.

7Follow-up questions

Why is Retry outermost by default?

So that each attempt is a separate, visible event to the circuit breaker, rate limiter and bulkhead. The breaker learns about every failed call to the dependency, the rate limiter counts retries against the limit, and the bulkhead does not hold a slot while Retry is waiting.

Should a fallback be on the Retry or the CircuitBreaker annotation?

Put it on the outermost layer that should handle failure, usually the circuit breaker or retry with a single fallback, so it runs once after all attempts and covers CallNotPermittedException. Declaring fallbacks on several annotations of one method makes the behaviour hard to reason about.

How would you verify the order in a test?

Make the dependency fail twice and succeed once, call the method through the Spring context, and then read the breaker's metrics: with Retry outside, it should report three calls with two failures. Forcing the breaker open and checking that only one attempt happens confirms the ignore rule.

8Conclusion

In this answer, we saw that Resilience4j's annotations nest as Retry ( CircuitBreaker ( RateLimiter ( TimeLimiter ( Bulkhead ( function ) ) ) ) ) by default. Retry is outermost, so every attempt is recorded by the breaker and spends a rate limiter permit, and the time limit applies per attempt. When the breaker is open, Retry must ignore CallNotPermittedException or it retries pointlessly. The order can be changed with aspect order properties, and @TimeLimiter needs CompletableFuture or reactive return types.

What to say in the interviewAbout 90 seconds aloud

Open with

The annotations are separate aspects nested around the method, and the default order is Retry around CircuitBreaker around RateLimiter around TimeLimiter around Bulkhead around the function. Retry being outermost means each attempt goes through all the inner layers.

Then, if they want more

So the circuit breaker records every attempt, three timeouts are three failures in its window, which is what we want for it to open promptly. The rate limiter spends a permit for each attempt, so retries count against the limit, and the time limit applies per attempt, so the total time can be several timeouts plus the backoff waits.

The bulkhead is innermost, so it only holds a slot while a call is actually running, not while Retry sleeps. The catch is that when the breaker opens, every attempt gets CallNotPermittedException immediately, and Retry, unless configured otherwise, retries it, which only adds delay. So I always put CallNotPermittedException in the retry's ignore-exceptions and handle it with a fallback.

If I need another order, there are aspect order properties for each module, and I would confirm the result in a test that counts breaker calls, or use the Decorators API so the order is explicit in code. Finally, @TimeLimiter only works on CompletableFuture or reactive return types; for blocking calls I rely on the HTTP client's read timeout.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "When several Resilience4j annotations are on one method (@Retry, @CircuitBreaker...": https://scrivio-interview-library.netlify.app/spring-boot/resilience/30eff1925a/