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-boot3bringsRateLimiter,Retry,TimeLimiter,CircuitBreaker, andBulkheadaspects.spring-boot-starter-aopis 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
- Context Propagation and Span Instrumentation
- Circuit Breakers and Bulkhead Isolation
- Rate Limiting, Retry, and Time Limiters
- Correlating Logs, Metrics, and Traces