Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Provides fault tolerance patterns for Spring Boot 3.x using Resilience4j. Use when implementing circuit breakers, handling service failures, adding retry logic with exponential backoff, configuring rate limiters, or protecting services from cascading failures. Generates circuit breaker, retry, rate limiter, bulkhead, time limiter, and fallback implementations. Validates resilience configurations through Actuator endpoints.
.claude/skills/giuseppe-trisciuoglio-spring-boot-resilience4j/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-12 | ✗→✓ | ▲ Improved | 105% | 0% |
| case-13 | ✗→✓ | ▲ Improved | 144% | 0% |
| case-15 | ✗→✓ | ▲ Improved | 143% | 0% |
| case-07 | ✓→✓ | = Same ✓ | 92% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 98% | 0% |
Provides Resilience4j patterns (circuit breaker, retry, rate limiter, bulkhead, time limiter, fallback) for Spring Boot 3.x fault tolerance with configuration and testing workflows.
Add Resilience4j dependencies to your project. For Maven, add to pom.xml:
xml<dependency> <groupId>io.github.resilience4j</groupId> <artifactId>resilience4j-spring-boot3</artifactId> <version>2.2.0</version> // Use latest stable version </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>
For Gradle, add to build.gradle:
gradleimplementation "io.github.resilience4j:resilience4j-spring-boot3:2.2.0" implementation "org.springframework.boot:spring-boot-starter-aop" implementation "org.springframework.boot:spring-boot-starter-actuator"
Enable AOP annotation processing with @EnableAspectJAutoProxy (auto-configured by Spring Boot).
Apply @CircuitBreaker annotation to methods calling external services:
java@Service public class PaymentService { private final RestTemplate restTemplate; public PaymentService(RestTemplate restTemplate) { this.restTemplate = restTemplate; } @CircuitBreaker(name = "paymentService", fallbackMethod = "paymentFallback") public PaymentResponse processPayment(PaymentRequest request) { return restTemplate.postForObject("http://payment-api/process", request, PaymentResponse.class); } private PaymentResponse paymentFallback(PaymentRequest request, Exception ex) { return PaymentResponse.builder() .status("PENDING") .message("Service temporarily unavailable") .build(); } }
Configure in application.yml:
yamlresilience4j: circuitbreaker: configs: default: registerHealthIndicator: true slidingWindowSize: 10 minimumNumberOfCalls: 5 failureRateThreshold: 50 waitDurationInOpenState: 10s instances: paymentService: baseConfig: default
See @references/configuration-reference.md for complete circuit breaker configuration options.
Apply @Retry annotation for transient failure recovery:
java@Service public class ProductService { private final RestTemplate restTemplate; public ProductService(RestTemplate restTemplate) { this.restTemplate = restTemplate; } @Retry(name = "productService", fallbackMethod = "getProductFallback") public Product getProduct(Long productId) { return restTemplate.getForObject( "http://product-api/products/" + productId, Product.class); } private Product getProductFallback(Long productId, Exception ex) { return Product.builder() .id(productId) .name("Unavailable") .available(false) .build(); } }
Configure retry in application.yml:
yamlresilience4j: retry: configs: default: maxAttempts: 3 waitDuration: 500ms enableExponentialBackoff: true exponentialBackoffMultiplier: 2 instances: productService: baseConfig: default maxAttempts: 5
See @references/configuration-reference.md for retry exception configuration.
Apply @RateLimiter to control request rates:
java@Service public class NotificationService { private final EmailClient emailClient; public NotificationService(EmailClient emailClient) { this.emailClient = emailClient; } @RateLimiter(name = "notificationService", fallbackMethod = "rateLimitFallback") public void sendEmail(EmailRequest request) { emailClient.send(request); } private void rateLimitFallback(EmailRequest request, Exception ex) { throw new RateLimitExceededException( "Too many requests. Please try again later."); } }
Configure in application.yml:
yamlresilience4j: ratelimiter: configs: default: registerHealthIndicator: true limitForPeriod: 10 limitRefreshPeriod: 1s timeoutDuration: 500ms instances: notificationService: baseConfig: default limitForPeriod: 5
Apply @Bulkhead to isolate resources. Use type = SEMAPHORE for synchronous methods:
java@Service public class ReportService { private final ReportGenerator reportGenerator; public ReportService(ReportGenerator reportGenerator) { this.reportGenerator = reportGenerator; } @Bulkhead(name = "reportService", type = Bulkhead.Type.SEMAPHORE) public Report generateReport(ReportRequest request) { return reportGenerator.generate(request); } }
Use type = THREADPOOL for async/CompletableFuture methods:
java@Service public class AnalyticsService { @Bulkhead(name = "analyticsService", type = Bulkhead.Type.THREADPOOL) public CompletableFuture<AnalyticsResult> runAnalytics( AnalyticsRequest request) { return CompletableFuture.supplyAsync(() -> analyticsEngine.analyze(request)); } }
Configure in application.yml:
yamlresilience4j: bulkhead: configs: default: maxConcurrentCalls: 10 maxWaitDuration: 100ms instances: reportService: baseConfig: default maxConcurrentCalls: 5 thread-pool-bulkhead: instances: analyticsService: maxThreadPoolSize: 8
Apply @TimeLimiter to async methods to enforce timeout boundaries:
java@Service public class SearchService { @TimeLimiter(name = "searchService", fallbackMethod = "searchFallback") public CompletableFuture<SearchResults> search(SearchQuery query) { return CompletableFuture.supplyAsync(() -> searchEngine.executeSearch(query)); } private CompletableFuture<SearchResults> searchFallback( SearchQuery query, Exception ex) { return CompletableFuture.completedFuture( SearchResults.empty("Search timed out")); } }
Configure in application.yml:
yamlresilience4j: timelimiter: configs: default: timeoutDuration: 2s cancelRunningFuture: true instances: searchService: baseConfig: default timeoutDuration: 3s
Stack multiple patterns on a single method for comprehensive fault tolerance:
java@Service public class OrderService { @CircuitBreaker(name = "orderService") @Retry(name = "orderService") @RateLimiter(name = "orderService") @Bulkhead(name = "orderService") public Order createOrder(OrderRequest request) { return orderClient.createOrder(request); } }
Execution order: Retry → CircuitBreaker → RateLimiter → Bulkhead → Method
All patterns should reference the same named configuration instance for consistency.
Create a global exception handler using @RestControllerAdvice:
java@RestControllerAdvice public class ResilienceExceptionHandler { @ExceptionHandler(CallNotPermittedException.class) @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE) public ErrorResponse handleCircuitOpen(CallNotPermittedException ex) { return new ErrorResponse("SERVICE_UNAVAILABLE", "Service currently unavailable"); } @ExceptionHandler(RequestNotPermitted.class) @ResponseStatus(HttpStatus.TOO_MANY_REQUESTS) public ErrorResponse handleRateLimited(RequestNotPermitted ex) { return new ErrorResponse("TOO_MANY_REQUESTS", "Rate limit exceeded"); } @ExceptionHandler(BulkheadFullException.class) @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE) public ErrorResponse handleBulkheadFull(BulkheadFullException ex) { return new ErrorResponse("CAPACITY_EXCEEDED", "Service at capacity"); } }
Enable Actuator endpoints for monitoring resilience patterns in application.yml:
yamlmanagement: endpoints: web: exposure: include: health,metrics,circuitbreakers,retries,ratelimiters endpoint: health: show-details: always health: circuitbreakers: enabled: true ratelimiters: enabled: true
Access monitoring endpoints:
GET /actuator/health - Overall health including resilience patternsGET /actuator/circuitbreakers - Circuit breaker statesGET /actuator/metrics - Custom resilience metricsGET /actuator/circuitbreakers shows OPEN → wait waitDurationInOpenState → verify state transitions to HALF_OPEN → CLOSEDresilience4j.retry.metrics.enabled: true → invoke endpoint → verify retry.{instance}.successful-calls-with-retry-attempts metric increaseslimitForPeriod → verify 429 status → check GET /actuator/ratelimiters shows LIMITEDmaxConcurrentCalls → verify excess requests fail immediately with BulkheadFullExceptiontimeoutDuration → verify fallback triggers after timeoutSee @references/testing-patterns.md for unit and integration testing strategies.
exponentialBackoffMultiplier: 2)failureRateThreshold between 50-70%registerHealthIndicator: true for all patterns@Retry on non-idempotent operations like POST requestsjava// BEFORE: No protection public PaymentResponse processPayment(PaymentRequest request) { return restTemplate.postForObject("http://payment-api/process", request, PaymentResponse.class); } // AFTER: Circuit breaker with fallback @CircuitBreaker(name = "paymentService", fallbackMethod = "paymentFallback") public PaymentResponse processPayment(PaymentRequest request) { return restTemplate.postForObject("http://payment-api/process", request, PaymentResponse.class); } private PaymentResponse paymentFallback(PaymentRequest request, Exception ex) { return PaymentResponse.builder().status("PENDING").message("Service temporarily unavailable").build(); }
java// BEFORE: Single attempt public Order getOrder(Long orderId) { return orderRepository.findById(orderId).orElseThrow(() -> new OrderNotFoundException(orderId)); } // AFTER: Retry with exponential backoff @Retry(name = "orderService", maxAttempts = 3, waitDuration = @WaitDuration(500L), fallbackMethod = "getOrderFallback") public Order getOrder(Long orderId) { return orderRepository.findById(orderId).orElseThrow(() -> new OrderNotFoundException(orderId)); } private Order getOrderFallback(Long orderId, Exception ex) { return Order.cachedOrder(orderId); }
java// BEFORE: Unbounded requests @GetMapping("/api/data") public Data fetchData() { return dataService.process(); } // AFTER: Rate limited @RateLimiter(name = "dataService", fallbackMethod = "rateLimitFallback") @GetMapping("/api/data") public Data fetchData() { return dataService.process(); } private ResponseEntity<ErrorResponse> rateLimitFallback(Exception ex) { return ResponseEntity.status(429).body(new ErrorResponse("TOO_MANY_REQUESTS", "Rate limit exceeded")); }
See also: Configuration Reference · Testing Patterns · Examples · Resilience4j Docs · Actuator Skill
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-07 | pass→pass | 13,518 | 9,590 | -29% | 1 | 1 | 0% | 2,732 | 5,232 | +92% | 0 | 0 | — |
case-01 | pass→pass | 10,248 | 4,615 | -55% | 1 | 1 | 0% | 2,027 | 4,009 | +98% | 0 | 0 | — |
case-02 | pass→pass | 10,993 | 7,970 | -27% | 1 | 1 | 0% | 2,110 | 4,838 | +129% | 0 | 0 | — |
case-22 | pass→pass | 18,288 | 18,824 | +3% | 1 | 1 | 0% | 3,741 | 6,404 | +71% | 0 | 0 | — |
case-03 | pass→pass | 3,583 | 3,580 | -0% | 1 | 1 | 0% | 727 | 3,822 | +426% | 0 | 0 | — |
case-04 | pass→pass | 11,157 | 8,259 | -26% | 1 | 1 | 0% | 2,194 | 4,969 | +126% | 0 | 0 | — |
case-05 | pass→pass | 8,858 | 6,310 | -29% | 1 | 1 | 0% | 1,645 | 4,266 | +159% | 0 | 0 | — |
case-06 | pass→pass | 3,290 | 3,240 | -2% | 1 | 1 | 0% | 559 | 3,842 | +587% | 0 | 0 | — |
case-08 | pass→pass | 10,803 | 6,893 | -36% | 1 | 1 | 0% | 2,091 | 4,662 | +123% | 0 | 0 | — |
case-09 | pass→pass | 13,452 | 11,788 | -12% | 1 | 1 | 0% | 2,268 | 5,323 | +135% | 0 | 0 | — |
case-10 | pass→pass | 9,770 | 8,239 | -16% | 1 | 1 | 0% | 1,766 | 4,862 | +175% | 0 | 0 | — |
case-11 | pass→pass | 10,276 | 5,800 | -44% | 1 | 1 | 0% | 1,964 | 4,333 | +121% | 0 | 0 | — |
case-12 | fail→pass | 12,262 | 8,463 | -31% | 1 | 1 | 0% | 2,374 | 4,877 | +105% | 0 | 0 | — |
case-13 | fail→pass | 8,547 | 4,491 | -47% | 1 | 1 | 0% | 1,694 | 4,140 | +144% | 0 | 0 | — |
case-14 | pass→pass | 14,478 | 11,275 | -22% | 1 | 1 | 0% | 2,839 | 5,437 | +92% | 0 | 0 | — |
case-15 | fail→pass | 11,823 | 11,897 | +1% | 1 | 1 | 0% | 2,219 | 5,400 | +143% | 0 | 0 | — |
case-16 | pass→pass | 8,876 | 5,769 | -35% | 1 | 1 | 0% | 1,485 | 4,255 | +187% | 0 | 0 | — |
case-17 | pass→pass | 14,225 | 3,948 | -72% | 1 | 1 | 0% | 2,062 | 3,705 | +80% | 0 | 0 | — |
case-18 | pass→pass | 15,886 | 11,628 | -27% | 1 | 1 | 0% | 2,562 | 5,177 | +102% | 0 | 0 | — |
case-19 | pass→pass | 12,935 | 10,145 | -22% | 1 | 1 | 0% | 2,112 | 4,908 | +132% | 0 | 0 | — |
case-20 | pass→pass | 4,476 | 4,282 | -4% | 1 | 1 | 0% | 967 | 4,108 | +325% | 0 | 0 | — |
case-21 | pass→pass | 12,003 | 8,668 | -28% | 1 | 1 | 0% | 2,409 | 4,820 | +100% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +14 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.