0Pricing
Spring Boot 4 Complete Guide · Lesson

Rate Limiting, Retry, and Time Limiters

Combine rate limiters, retries, and timeouts to shape load and contain cascading failures.

Three Knobs for Shaping Load

Circuit breakers stop calling a dead dependency, but they are only one tool in the resilience toolbox. To shape inbound load and contain cascading failures you combine three more Resilience4j primitives:

  • RateLimiter — caps how many calls per time window are allowed to start. Excess callers wait or are rejected.
  • Retry — re-invokes a failed call a bounded number of times, ideally with backoff, to ride out transient errors.
  • TimeLimiter — caps how long a single call may run before it is cancelled, freeing the thread and bounding tail latency.

Used together they protect both you (don't overload your own service) and your downstream (don't hammer a struggling dependency).

Adding Resilience4j to Spring Boot 4

Spring Boot 4 integrates Resilience4j through the Spring Cloud Circuit Breaker / resilience4j-spring-boot3 starter, which exposes annotation-driven aspects for every primitive.

Add the starter and AOP support so the annotations are woven in:

  • resilience4j-spring-boot3 brings RateLimiter, Retry, TimeLimiter, CircuitBreaker, and Bulkhead aspects.
  • spring-boot-starter-aop is required — the annotations are implemented as AOP advice.
  • Metrics flow into Micrometer automatically when Actuator is present.
<dependencies>
  <dependency>
    <groupId>io.github.resilience4j</groupId>
    <artifactId>resilience4j-spring-boot3</artifactId>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
  </dependency>
</dependencies>

All lessons in this course

  1. Context Propagation and Span Instrumentation
  2. Circuit Breakers and Bulkhead Isolation
  3. Rate Limiting, Retry, and Time Limiters
  4. Correlating Logs, Metrics, and Traces
← Back to Spring Boot 4 Complete Guide