Unit 11 of 13 · about 4 hours · derive, measure

Bounded queues, end-to-end backpressure, overload rejection and retry amplification

An unbounded queue turns overload into unbounded latency and then collapse. Explicit rejection plus a bounded retry budget keeps one slow hop from sinking the stack.

You'll be able to

  • Derive queue bounds from latency objectives and explain end-to-end versus hop-local backpressure.
  • Implement bounded queues with explicit rejection codes and a retry budget that pauses under throttle.
  • Measure amplification under overload and compare two shedding policies on one workload.

Covers

Bounded queues and end-to-end backpressureOverload rejection and retry amplification
1

Read

In this order, only the parts listed

0 of 2 done

  1. AWS retries: amplification and token-bucket throttleAWS Builders' Library - Timeouts, Retries and Backoff with Jitter

    Retries and backoff: the 243x five-layer example, retry at one layer, token-bucket local retry limit; Timeouts: pick from downstream latency percentiles such as p99.9 for a 0.1 percent false-timeout rate

  2. HLD resilience and rate limitingHLD Handbook - Networking, API Design and Backpressure

    Resilience Patterns: timeouts, retries with backoff and jitter, breakers, bulkheads and the DynamoDB 2015 retry-storm case as a reported example; plus the Rate Limiting chapter for token, leaky, fixed and sliding windows with 429 plus Retry-After

2

Focus on

  • Bound every queue and name what happens at the bound: drop newest, drop oldest, or reject with RESOURCE_EXHAUSTED. An unnamed bound is an unbounded queue with extra steps.
  • Hop-local backpressure protects one process; end-to-end backpressure protects the chain. Retry budgets and throttles are the end-to-end half, and they must pause together.
  • Rejection is a feature with a code. gRPC RESOURCE_EXHAUSTED, or HTTP 429 with Retry-After, lets callers back off; silent queueing lets them time out and retry blindly, which amplifies.
  • The Systems units on bounded queues, admission and backpressure and on retry budgets, circuit breaking and load shedding taught the primitives. Here the new work is the RPC-wide budget and the measured comparison.
Common mistakes · 3
  • Adding capacity to fix a retry storm. Correlated retries saturate the dependency faster than capacity arrives; pause retries first, then scale.
  • Breaking the circuit and calling it fixed. Breakers add modal behavior and slow recovery; prefer bounded budgets and throttles with measured half-open probing.
  • Returning UNAVAILABLE for every overload. Distinguish retryable transient from shed load with RESOURCE_EXHAUSTED, so callers do not retry what you just refused to do.
3

Try it yourself

Closed-book, before checking anything

Closed-book, derive and the token-pause rule, then run one workload at two overload levels and report offered versus admitted versus rejected versus retried counts with p50 and p99 for each policy.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Offered load doubles past saturation with an unbounded queue. What do latency and retries do?Answer

    Queueing delay grows without bound, timeouts fire, callers retry, and retries add load past saturation. Latency diverges and goodput falls; a bound plus rejection stops this loop.

  2. 2.Why retry at one layer instead of every layer?Answer

    Per-layer retries multiply to downstream. One bounded retry point with fail-fast errors elsewhere caps amplification while preserving availability on transient faults.

  3. 3.When does the gRPC-style token throttle pause retries?Answer

    When the per-server token count falls below half of maxTokens. Failures decrement by 1 and successes refund tokenRatio, so sustained failure pauses retries automatically.

  4. 4.A dependency reports p99.9 at 800 ms. Where do you set the timeout and why?Answer

    Start at the p99.9, 800 ms, which accepts about 0.1 percent false timeouts, then pad for network variance; the HLD chapter's example pads it to 2,000 ms. Too low creates false timeouts and retry storms; too high stops protecting threads and ports. Check the choice with a load test on your machine.

5

Practice

  • Design a Sliding Window Log Rate Limiter

    Implement exact sliding-window admission over request timestamps

    The judge checks admission logic only. Pair it with the token-bucket problem below and measure both under one bursty workload with rejection counts.

  • Design a Token Bucket Rate Limiter

    Implement refill plus burst admission and compare with the sliding-window policy on the same trace

    Report admitted, rejected and retried counts with p50 and p99 on your machine, labeled as one example, not a target.

You're done when

Your bounded queue rejects with codes at the bound, retries pause under throttle, and your two-policy comparison names which overload region each policy wins.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 14 more in the section
  • 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 - 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.

  • 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.

  • 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.

  • 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.