Spring / Spring Retry Interview Questions
What is the @Backoff annotation and how does it control retry delays?
The @Backoff annotation is a nested annotation used within @Retryable to define the waiting strategy between consecutive retry attempts. Without a backoff, retries happen immediately one after another, which can overwhelm a struggling resource. @Backoff introduces controlled delays to give the failing resource time to recover.
Key attributes:
| Attribute | Default | Description |
|---|---|---|
| delay | 1000ms | Initial delay in milliseconds before the first retry |
| maxDelay | 0 (no cap) | Maximum allowed delay in milliseconds |
| multiplier | 0 (no multiplier) | Multiplies the delay after each attempt (exponential) |
| random | false | Adds jitter to the delay to avoid thundering herd |
Example — exponential backoff with a cap:
@Retryable( retryFor = TimeoutException.class, maxAttempts = 5, backoff = @Backoff(delay = 500, multiplier = 2, maxDelay = 8000) ) public void syncData() { ... }
With this configuration, delays will be 500ms → 1000ms → 2000ms → 4000ms → capped at 8000ms. Setting random = true adds slight variation to each interval, which is important in high-concurrency scenarios to prevent all retry clients from hitting the same resource simultaneously.
More Related questions...