Spring / Resilience4j Interview questions
How can you optimize retry strategies to avoid retry storms?
A retry storm happens when many clients (or many concurrent requests on one client) all retry a failing dependency at roughly the same moments, effectively multiplying the load on a system that's already struggling and making recovery harder instead of easier.
Use IntervalFunction.ofExponentialRandomBackoff instead of a fixed or plain exponential delay, since the added jitter spreads retry attempts out in time instead of letting every client's Nth retry land in the same instant.
Cap maxAttempts conservatively rather than assuming more retries is always safer - each additional attempt adds more load precisely when the dependency is least able to handle it, and a request that's failed three times in a row is rarely going to succeed on a fourth blind attempt.
Pair Retry with a CircuitBreaker so that once the dependency is confirmed unhealthy, the breaker opens and stops permitting further retry attempts entirely, rather than continuing to retry against a call that's now being rejected before it even reaches the dependency.
Finally, scope retries to genuinely idempotent operations and genuinely transient exception types - retrying a non-idempotent write, or retrying an error that reflects a permanent problem, adds risk and load without adding any real chance of success.
More Related questions...