Retries help with transient failures, but how you space them determines whether they help or make things worse. Problem with static (fixed) retry delays - If a dependency is overloaded or briefly down, every client retries after the same fixed delay (for example exactly 1 second). All retries arrive at the same moment, creating synchronised waves of traffic — the "thundering herd" or retry storm. - A struggling service receives even more load exactly when it needs relief, which can turn a brief slowdown into a prolonged outage. - Fixed short delays may not give the dependency enough time to recover (for example during a database failover lasting 20–30 seconds). Exponential backoff - Each retry waits longer than the previous one: for example 200 ms, 400 ms, 800 ms, 1.6 s. - Transient blips are retried quickly, while longer problems get progressively more breathing room. - Total retry load on the dependency decreases over time. Jitter (randomness) - Exponential backoff alone still synchronises clients that failed at the same time: all of them retry at 200 ms, then at 400 ms, and so on. - Adding random jitter spreads retries over a time window (for example a random value between 0 and the calculated delay, often called "full jitter"), so retries arrive smoothly instead of in spikes. - AWS and others have published analyses showing jittered backoff significantly reduces contention and completes work faster overall. Polly configuration example (.NET 8+, Polly v8) new RetryStrategyOptions { MaxRetryAttempts = 4, BackoffType = DelayBackoffType.Exponential, UseJitter = true, // decorrelated jitter in Polly v8 Delay = TimeSpan.FromMilliseconds(200), ShouldHandle = new PredicateBuilder().Handle<HttpRequestException>().Handle<TimeoutRejectedException>() } Complementary practices - Cap the maximum delay and number of attempts, and set an overall timeout so retries fit in the request's time budget. - Retry only transient errors (timeouts, 503, 429, connection failures) and only idempotent operations, or use idempotency keys. - Respect Retry-After headers from the server. - Combine with a circuit breaker, so during a sustained outage you stop retrying and fail fast. - Monitor retry counts; rising retries are an early warning of dependency problems. Summary answer: "Static retries synchronise clients and hammer a struggling service. Exponential backoff gives it time to recover, and jitter spreads retries out so they don't arrive in waves."
Ravindra Wadile · · 0 likes