Spring / Spring Boot 4 Basics Interview Questions
What are @Retryable and @ConcurrencyLimit in Spring Boot 4 and how do they work?
Spring Boot 4 (via Spring Framework 7) brings built-in resilience patterns directly into the Spring context. Previously, retry required the separate spring-retry dependency plus @EnableRetry. Spring Boot 4 ships these capabilities as first-class features.
// Spring Boot 3 (required separate dependency + @EnableRetry): // pom.xml: spring-retry dependency // Config class: @EnableRetry @Service public class StockService { @Retryable(value = {NetworkException.class}, maxAttempts = 2) public void updateStock() { ... } } // Spring Boot 4: works out of the box with spring-boot-starter-resilience // No @EnableRetry needed! @Service public class StockService { // Retry with exponential backoff and jitter @Retryable( includes = NetworkException.class, // exception types to retry on maxRetries = 3, // number of retry attempts backoff = @Backoff( delay = 500, // initial delay in ms multiplier = 2.0, // exponential multiplier random = true // add jitter ) ) public Order fetchOrderFromRemote(String orderId) { return remoteService.fetch(orderId); // automatically retried on NetworkException } // Bulkhead pattern: limit concurrent callers @ConcurrencyLimit(limit = 5) // max 5 concurrent executions public void processPayment(Payment payment) { // Only 5 threads can execute this simultaneously // 6th caller blocks until one slot frees up paymentGateway.process(payment); } // Combining both: @Retryable(includes = NetworkException.class, maxRetries = 3) @ConcurrencyLimit(limit = 10) public void updateStock() { externalInventoryApi.update(); } }
@ConcurrencyLimit implements the Bulkhead pattern from resilience engineering. It is particularly valuable with virtual threads (Java 21+), where it prevents a burst of cheap virtual threads from overwhelming a downstream service with simultaneous requests.
More Related questions...