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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
