Highlights

Contents

Part IV
04

Retries, exponential backoff, and jitter

We recover transient failures without repeating irreversible effects or multiplying demand. An uncertain outcome and a permanent rejection need different responses. We will classify failures, calculate backoff, spread retries, and give one layer a bounded retry budget.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1Availability and SPOFs2Redundancy,active-active, passive3Graceful degradation andfault tolerance4Retries, exponentialbackoff, and jitter5Timeouts, circuitbreakers, bulkheads6Health checks andfailover7Disaster recovery, RTO,and RPO8Case study: one incident

#Section 13Which failures deserve a retry?

A malformed score correction will remain malformed after a delay. A connection interrupted before any command was sent may work on another attempt. A lost reply after commit is different again. A retry is another attempt to complete the same logical operation, and that identity is part of its safety.

Classify the outcome first. Validation or permission failures require a corrected request or changed permission. Transient transport failures may permit another attempt if the deadline and budget allow it. Uncertain writes require a stable command key and recovery of the original result, because blindly creating a new write can duplicate the effect.

SORT THE FAILURE BEFORE CHOOSING A RETRYSORT THE FAILURE BEFORE CHOOSING A RETRYinvalid requestpermanentfix the requestpeer unavailablemaybe transientbounded attemptreply lostoutcome uncertainrecover the same command
Figure 11.14Three different failure classes. The application chooses whether an operation is safe to repeat.

For a command that adds a score delta, repeating the bytes is insufficient. The service must attach the same operation identity. A separate genuinely new correction uses a new identity even if its content is identical. Amazon’s idempotent API discussion motivates this distinction.

#Section 14Exponential backoff

Every failed request retries immediately, so a brief interruption produces another burst before the server recovers. Exponential backoff increases the delay ceiling between repeated attempts. It reduces repeated pressure and gives transient causes time to change, while a cap bounds an individual delay.

bk=min⁡(bmax⁡,b02k).b_k=\min(b_{\max},b_0 2^k).

Read this as attempt index kk gets a ceiling equal to the smaller of maximum delay bmax⁡b_{\max} and initial delay b0b_0 doubled kk times. With illustrative initial delay 100 milliseconds and ceilings below the cap, the first values are 100, 200, 400, and 800 milliseconds.

b = min(b_max, 100 × 2^k): CEILINGS 100, 200, 400, 800 MSb = min(b_max, 100 × 2^k): CEILINGS 100, 200, 400, 800 MSwait ≤ 100wait ≤ 200wait ≤ 400wait ≤ 800skip the retry if the remaining deadline cannot cover the wait and the calla delay cap is not a total deadline
Figure 11.15Illustrative backoff ceilings. A retry is skipped when the request has no remaining useful budget.

The cap does not stop infinite attempts. Limit attempt count, overall time, and service-wide retry rate separately. A long-lived background task may have a different retry horizon from a viewer's interactive read. Store its progress so that a process restart does not reset all waiting work into an immediate burst.

#Section 15Jitter spreads the same recovery work

A fleet with identical delays retries together. Jitter is randomness added to retry timing so failures do not synchronize another surge. Under full jitter, choose a delay uniformly between zero and the current backoff ceiling.

Jk∼U(0,bk),E[Jk]=bk/2.J_k\sim U(0,b_k),\qquad E[J_k]=b_k/2.

Read this as the delay JkJ_k is uniform over the interval ending at ceiling bkb_k, so its mean is half that ceiling. For ceilings 100, 200, 400, and 800 milliseconds, the means are 50, 100, 200, and 400 milliseconds. These are distribution means, not promised delays for individual callers.

FIXED 400 MS BACKOFF RETURNS EVERYONE AT ONCE; FULL JITTER SPREADS THEM OVER 0–400FIXED 400 MS BACKOFF RETURNS EVERYONE AT ONCE; FULL JITTER SPREADS THEM OVER 0–400fixedjittered0100200300400 msexpected wait 200 ms; the number of attempts is unchanged (illustrative samples)
Figure 11.16Illustrative delay distribution. Randomizing time does not reduce the number of attempts by itself.

Use an actual random source and keep the chosen delay within the remaining deadline. Do not describe jitter as fairness: a random short wait can favor one caller by chance. Admission policy supplies fairness; jitter reduces synchronized load. The Builders’ Library discusses these distinct controls.

#Section 16One retry owner and a retry budget

A gateway, application, and database wrapper each allow three attempts. One logical request can then become 3 times 3 times 3, or 27 database attempts. This multiplication is why a locally reasonable policy can create a globally unreasonable workload.

Give the layer with enough semantic knowledge ownership of retries. Lower layers should report failures promptly and expose whether work might have committed. An illustrative service-wide budget permits retry traffic of at most 10% of 1,000 original requests per second, or 100 retries per second. The attempt policy still limits each request separately.

THREE ATTEMPTS AT EACH OF THREE LAYERS TURN 1 OPERATION INTO 27 DATABASE CALLSTHREE ATTEMPTS AT EACH OF THREE LAYERS TURN 1 OPERATION INTO 27 DATABASE CALLSoperation: 1gateway: 3service: 9database: 27
Figure 11.17Each layer permits three total attempts. Independent retry ownership produces the product.
RETRIES MAY ADD AT MOST 10%: 100/S ON TOP OF 1,000/S ORIGINALSRETRIES MAY ADD AT MOST 10%: 100/S ON TOP OF 1,000/S ORIGINALS1,000/s original (each = 100/s)+100/sbudget spent: fail fasta retry still needs time left on the deadline and a safe identity
Figure 11.18Illustrative budget. Retries still require a remaining deadline and a safe operation identity.