Unit 6 of 13 · about 3 hours · explain, implement
Ambiguous outcomes after timeout and monotonic deadline propagation
A timeout reports the reply was late, not that the work did not happen. Systems that treat timeout as failure retry blindly and double-apply effects.
You'll be able to
- Enumerate the four timeout windows: before receive, during execution, after side effect, during response.
- Explain why a timeout never proves the effect did not happen, and how
ErrMaybereports that. - Propagate a monotonic deadline across hops by converting to remaining timeout at each hop.
Covers
Read
In this order, only the parts listed
0 of 3 done
- MIT 6.5840 Lecture 2 RPC failure sectionMIT 6.5840 - RPC and Threads plus Lab 2 Key/Value Server
Remote Procedure Call, RPC problem: what to do about failures: client never sees a response and does not know if the server saw the request; best-effort retry and at-most-once discussion with
kv.go - MIT 6.5840 Lab 2 unreliable network and ErrMaybeMIT 6.5840 - RPC and Threads plus Lab 2 Key/Value Server
Key/value server with dropped messages: retry with
time.Sleep(100 * time.Millisecond)until a reply arrives; returnErrMaybeon a retriedPutthat answersErrVersion - gRPC deadlines guidegRPC Guides - Deadlines, Cancellation, Status Codes, Retry and Flow Control
Overview and Deadlines on the Client and Server: always set a deadline,
DEADLINE_EXCEEDEDon the client,CANCELLEDon the server; Deadline Propagation converts the point in time to a remaining timeout to avoid clock skew
Focus on
- Four windows, four different truths: dropped before receive means nothing ran, during execution means unknown progress, after side effect means done but unreported, during response means done with a lost reply. The client sees one event: no reply in time.
ErrMaybeis the honest answer for a retried conditional write that meets a version mismatch. The first attempt may have applied and its success reply was lost, or another client may have moved the version first.- The Systems units on cancellation, deadlines and shutdown state machines and on deadlines, retries and idempotency across RPC taught timer mechanics and remaining-time propagation. Here the new work is reporting ambiguity to the caller and testing each timeout window against an unreliable network.
- The server handler must check cancellation and stop spawned work. gRPC cancels the call, but it cannot interrupt application code that never checks.
Common mistakes · 3
- Treating a timeout as a failed effect. A timeout proves only that no reply arrived before the timer; the effect may have completed.
- Returning
ErrVersionfor a retried write. On a first attempt it means not applied, but on a retry it is ambiguous, so the client must report maybe, not no. - Propagating an absolute timestamp across machines. Clock skew shifts it; propagate the remaining budget computed on a monotonic clock at each hop.
Try it yourself
Closed-book, before checking anything
ErrMaybe exactly when a retried Put meets ErrVersion.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.A
Putreply is lost and the retry getsErrVersion. Did the firstPutrun?AnswerUnknown. Either the first
Putapplied and its success reply was lost, or another client changed the version first. The Clerk must returnErrMaybe.2.Why is a
Getsafe to retry but a conditionalPutis not?AnswerA
Getchanges no state, so duplicates are harmless. A conditionalPutchanges state once, and a blind retry can apply it twice or hide whose write won.3.A client sets a 2 s deadline and the server spends 0.5 s before calling downstream. What timeout goes downstream?Answer
At most the remaining 1.5 s, recomputed on the monotonic clock. The downstream budget is the original point in time minus elapsed time, never the full 2 s again.
4.The server notices cancellation but keeps computing to reply anyway. What breaks?Answer
Wasted work and resource exhaustion under load, plus a reply the client already abandoned. The handler must stop and release, and propagate cancellation to its own downstream calls.
Practice
- MIT 6.5840 Lab 2: Key/Value server with dropped messages
Implement
kvsrv1/client.goretry loop and passTestUnreliableNetplus the lock testsTestOneClientUnreliableandTestManyClientsUnreliablePublic tests for Spring 2026. Do not publish solutions. Then add a four-window fault log that records which window each injected timeout exercised.
You're done when
You can place any timeout in one of the four windows, your Clerk returns ErrMaybe exactly on ambiguous retries, and downstream calls always carry the remaining budget.
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.
- MIT 6.5840 - RPC and Threads plus Lab 2 Key/Value ServerMIT PDOS · required
Read the Lecture 2 notes (
notes/l-rpc.txtandnotes/kv.go) on RPC failure and at-most-once execution, then do Lab 2: a versionedPutkey/value server whose client returnsErrMaybewhen a retriedPutmay 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.
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.
- 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.pyscript and its--laband--partoptions. 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 - 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.
- 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.