When a payment service stumbles, immediate retries can turn a brief glitch into a traffic jam. Exponential backoff gives the service breathing room by multiplying the wait between successive failed attempts instead of repeatedly hammering it. section 10.2.2
A polite second chance
After the first failure, wait 1 second before retrying. If the next attempt fails, wait 2 seconds; then 4 seconds after another failure. With a multiplier of 2, the next wait would be 8 seconds, provided another retry is allowed. section 10.2.2 section 10.8
Use retries for temporary failures, such as a network blip or HTTP 503, not for errors unlikely to improve on another attempt, such as invalid requests or authentication failures. Choose a retry limit and multiplier deliberately; extra attempts can help with glitches but also extend the customer's wait. section 10.1 section 10.8
A retry can repeat an action that already succeeded. For payments, generate an idempotency key and pass the same key with every attempt so the service can recognize the same transaction rather than charge the customer twice. section 10.2.2
Listing 12.3 The Retry Storm
public async Task ProcessPaymentAsync(Order order)
{
int retryCount = 0;
bool success = false;
while (!success && retryCount < 3) #A
{
try
{
var response = await _httpClient.PostAsync(
"http://payment-api/charge", order);
response.EnsureSuccessStatusCode();
success = true;
}
catch (HttpRequestException)
{
retryCount++; #B
_logger.LogWarning(
$"Payment timeout. Firing retry attempt {retryCount}...");
}
}
}This retry loop has a limit but no delay. When many clients run it together, even a brief slowdown can multiply traffic into a retry storm. section 12.8.3
Backoff is one shock absorber, not the whole suspension. Add random jitter to the waits, use a circuit breaker to fail fast when the downstream service is struggling, and plan a fallback if attempts are exhausted. For example, a checkout can queue an order for later payment processing. section 12.8.3 section 10.4.2










