Spring / Resilience4j Interview questions
Explain the internal working of exponential backoff in the Retry module?
Exponential backoff increases the wait time between successive retry attempts rather than using the same fixed delay every time, which spreads out repeated load on a struggling dependency instead of hammering it at a constant rate.
Resilience4j implements this through the IntervalFunction abstraction: IntervalFunction.ofExponentialBackoff(initialInterval, multiplier) computes each wait as initialInterval * multiplier^(attempt - 1), so with a 500ms initial interval and a 2x multiplier, the waits go 500ms, 1000ms, 2000ms, 4000ms, and so on.
IntervalFunction.ofExponentialRandomBackoff adds jitter on top of that formula, randomizing each wait within a range around the computed value - this matters specifically when many client instances retry the same failing dependency simultaneously, since pure exponential backoff without jitter still lets every client retry in lockstep and re-create the same load spike each round, while jitter spreads those retries out in time.
An optional maxInterval caps how large the wait can grow, preventing a client from waiting an unreasonably long time after many attempts on a long-lived retry configuration.
More Related questions...