liveBook · Manning

Exponential backoff

As explained in Grokking Software Architecture

Exponential backoff is a retry technique that increases the waiting interval after successive failures, typically by multiplying the interval by a constant factor.

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

How Grokking Software Architecture covers it

How deep it goes
Explains multiplied delays and retry limits, and mentions jitter without specifying how to calculate it.
Examples
Uses doubling delays and a payment API retry storm, plus a checkout exercise for choosing retry limits and a multiplier.
What you can do after
Evaluate retry policies by distinguishing transient failures, choosing limits and delays, and accounting for duplicate payments.
How it connects
Connects retries with idempotency keys, circuit breakers, timeouts, and fallbacks.

Also explained in

Compare how 11 books explain exponential backoff →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.