Unit 7 of 13 · about 4 hours · derive, implement

Bounded retries, exponential backoff with jitter and duplicate-suppression state

Unbounded per-layer retries turn one slow dependency into hundreds of downstream requests. The bound, the backoff and the dedup store are one design, not three.

You'll be able to

  • Derive the worst-case request multiplier for retries at every layer of a call chain.
  • Implement capped exponential backoff with jitter and a bounded retry budget including a token-bucket throttle.
  • Size duplicate-suppression state and its retention from the retry envelope.

Covers

Bounded retries across dependency hopsExponential backoff and randomized jitterDuplicate suppression state and retention limits
1

Read

In this order, only the parts listed

0 of 2 done

  1. AWS timeouts, retries and backoff with jitterAWS Builders' Library - Timeouts, Retries and Backoff with Jitter

    Retries and backoff: three tries at each of five layers give 243x load, retry at a single point in the stack; token-bucket retry throttle; Jitter: spread periodic and retry timers

  2. gRPC retry guidegRPC Guides - Deadlines, Cancellation, Status Codes, Retry and Flow Control

    Retry configuration: enabled by default with no default policy, no retry once response headers arrive; example maxAttempts 4 with initialBackoff 0.1s, maxBackoff 1s, multiplier 2 and jitter plus or minus 20 percent; retryThrottling with maxTokens and tokenRatio

2

Focus on

  • The Systems unit on deadlines, retries and idempotency across RPC derived layered amplification: with tries at each of layers the bottom sees , so three tries at five layers is . Here the new work is the jittered schedule, the token throttle and the size of the dedup store.
  • Backoff without jitter still thunders. Independent uniform jitter spreads the retry front so one recovery does not become the next overload spike.
  • The throttle is a separate bound from the attempt count: per server, failures consume tokens and successes refund a fraction, and retries pause when tokens fall below half.
  • Dedup retention must cover the maximum retry age plus clock and queue delay. A retry older than the store looks new.
Common mistakes · 3
  • Retrying at every layer for safety. Each layer multiplies the one below, so bound retries at one layer and let the others fail fast with a clear error.
  • Using fixed backoff under overload. Synchronized waiters return together and re-overload the dependency; jitter is the decorrelation, not a nicety.
  • Sizing dedup by the happy path. Size by the worst-case retry age times the peak request rate, plus a margin for queues and clock skew.
3

Try it yourself

Closed-book, before checking anything

Closed-book, derive for three tries at five layers, then compute a capped backoff schedule with base 0.1 s, multiplier 2, cap 1.0 s and uniform jitter in applied after the cap: with Python's random.Random(7) and one uniform(0.8, 1.2) draw per delay, the five delays in ms are 93.0, 172.1, 424.1, 663.2 and 1014.4.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Five layers each retry twice more on failure. What is the worst-case downstream multiplier?Answer

    . Each layer triples the load it received, so the bottom sees 243 requests for one top-level call.

  2. 2.Why does gRPC refuse to retry after response headers arrive?Answer

    The call is committed: the server may have produced effects the client has seen. Replaying history after that point can double-apply.

  3. 3.With maxTokens 10 and tokenRatio 0.1, when do retries pause?Answer

    Each failure removes 1 token and each success adds 0.1. When the count falls below 5, half of the maximum, retries pause until successes refill it.

  4. 4.A retry arrives 70 minutes late but dedup retains 60 minutes. What happens?Answer

    It executes as a new request. Retention bounds the suppression promise, so the contract must name the 60-minute window and callers must handle late duplicates beyond it.

5

Practice

  • Building Distributed Systems: RP-5 exponential backoff and TH-3 deduplication

    RP-5 exponential backoff, then TH-3 deduplication with LRU cache at /tracks/messenger/tasks/task-1-3-3-deduplication

    Tasks are graded in the browser after login, so treat a pass as a drill and keep your seeded backoff schedule plus bounded dedup store as the evidence.

  • Classify Retry Outcomes

    Implement classify(failures, maxRetries) delivering versus dead-letter routing after the retry budget

    The judge checks budget-exhaustion routing only. Add jitter and a token-bucket throttle in your own client and state what the judge does not establish.

You're done when

You derive 243 without notes, your seeded schedule matches to the millisecond, and your client pauses retries when tokens run dry while duplicates stay suppressed inside retention.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 14 more in the section
  • gRPC Guides - Deadlines, Cancellation, Status Codes, Retry and Flow ControlgRPC Authors · required

    Read the deadlines, cancellation, status codes, retry (enabled by default with no default policy; no retry once response headers arrive), keepalive and flow-control guides. Turn each into a rule your own RPC layer follows, and check a claim against grpcio before you rely on it.

  • AWS Builders' Library - Timeouts, Retries and Backoff with JitterAmazon Web Services · required

    Read the whole article for timeout choice, retries at one layer, retry amplification across hops, capped exponential backoff and jitter. Derive the request multiplier for retries at every layer of a call chain before writing your retry policy.

Also in this section

  • DDIA 2e - Chapter 5 Encoding and EvolutionMartin Kleppmann and Chris Riccomini · primary

    Read formats, schema evolution, service RPC, durable workflows and event-driven dataflow. Write a four-version compatibility table and connect each compatibility claim to a wire fixture.

  • Protocol Buffers and Avro - Unknown Fields and Schema ResolutionGoogle and the Apache Software Foundation · required

    Read the proto3 guide on field numbers, defaults and unknown fields (kept through binary parsing and reserialization, lost through JSON) and the Avro 1.12.0 schema resolution rules (https://avro.apache.org/docs/1.12.0/specification/). Build round-trip fixtures that show each rule.

  • Building Distributed Systems - The MessengerBuild Distributed Systems · support

    Track 1 is free: do the RPC subtrack (sync RPC with timeout, timeout and retry loop, async callbacks, callback reaper, exponential backoff) and the deduplication task. Tasks are graded in the browser after login, so treat a pass as a drill and keep your local harness as the evidence.

  • MIT 6.5840 - RPC and Threads plus Lab 2 Key/Value ServerMIT PDOS · required

    Read the Lecture 2 notes (notes/l-rpc.txt and notes/kv.go) on RPC failure and at-most-once execution, then do Lab 2: a versioned Put key/value server whose client returns ErrMaybe when a retried Put may already have run, and a lock built on it. Keep the course tests, then add cancellation, size-limit and mixed-version faults in your own harness.

  • DSLabs - Lab 1 Exactly-Once RPCUniversity of Washington (Ellis Michael) · support

    Labs are Java 21 message-passing state machines tested on an emulated network and by model-checking search tests that print a minimal violating trace; run them with the run-tests.py script and its --lab and --part options. Lab 1 builds an "exactly-once" RPC abstraction for an unreplicated key/value server on a network that drops, duplicates and reorders messages. Use it to check your request identity and duplicate-suppression design against exhaustive orderings.

  • HLD Handbook - Networking, API Design and BackpressureHLD Handbook · required

    Read only Part 0 networking and API design, then the load balancer, service discovery, rate limiting and reliability chapters needed for the protocol design. Use the diagrams to review boundaries, not as a substitute for fault tests.

  • AWS Builders' Library - Making Retries Safe with Idempotent APIsAmazon Web Services · support

    Read the caller-provided client request identifier pattern, the validation error for a repeated identifier with different parameters, the semantically equivalent response to a retry and why the identifier is retained only for a bounded interval. Compare that interval with your own duplicate-suppression state.

  • Building Distributed Systems - The NetworkerBuild Distributed Systems · optional

    Only the first three tasks are free (TCP echo, connection pool and backlog, graceful shutdown and drain). Tasks are graded in the browser after login, so treat a pass as a drill and keep your local harness as the evidence.

  • Beej's Guide to Network ProgrammingBrian Hall · support

    Use the client, server, send, receive, select or poll, and partial-transfer sections when socket behavior is unclear. This is a protocol mechanics reference, not the distributed-systems spine.

  • AlgoMaster System Design - Selected Networking and API ProblemsAlgoMaster · optional

    Use the problems on idempotency and retries (Deduplicate Idempotent Requests, Build an Idempotent Consumer, Classify Retry Outcomes), rate limiting (sliding-window log and token bucket), the Least Requests load balancer and the queue visibility timeout. For every solved component, add an external fault test and explain what its simplified judge does not establish.

  • Replicated Log and Stream Processor - Protocol SliceRoadmap-Final · support

    Create the repository, message schema, request and node identities, deadline and retry contract, deterministic network scheduler and raw event format. Keep this same artifact through DS-9.

  • RFC 9000 - QUIC Version 1IETF · reference

    Read Section 2 (streams), Section 4 (flow control) and Section 9 (connection migration) for QUIC transport behavior. No implementation; compare with TCP behavior from the Systems stage.

  • RFC 9114 - HTTP/3IETF · reference

    Read Sections 3 (connection setup), 6 (stream mapping) and 7 (framing) for how HTTP semantics map onto QUIC streams.

  • W3C Trace ContextW3C · reference

    Read Section 3.2 (traceparent fields), Section 3.3 (tracestate) and Section 4 (processing model) for trace correlation without synchronized clocks.