Unit 12 of 13 · about 4 hours · implement
Trace correlation without synchronized clocks and a deterministic faulty network
Clocks lie across machines, but IDs do not. A deterministic faulty network turns he-said-she-said debugging into a replayable history with a seed.
You'll be able to
- Correlate a request across client and server logs using trace and span IDs without comparing timestamps.
- Implement a seeded faulty network with delay, drop, duplicate, reorder, disconnect, corrupt, restart and cancel injection.
- Retain seeds and raw histories so any failure replays exactly.
Covers
Read
In this order, only the parts listed
0 of 2 done
- W3C traceparent, tracestate and processing modelW3C Trace Context
Section 3.2 traceparent: version, 16-byte trace id, 8-byte parent id and flags with sampled bit; Section 3.3 tracestate vendor pairs; Section 4 processing model for forwarding versus participating
- DSLabs Lab 1 exactly-once RPCDSLabs - Lab 1 Exactly-Once RPC
README Parts 2 and 3: at-least-once with sequence numbers then exactly-once shim; Resend/Discard versus Tick timer patterns; search tests that print minimal violating traces
Focus on
- Correlate by identifiers, order by causality. A
traceparentlike00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01links the hops; timestamp comparison across machines proves nothing about order. - The Systems unit on RPC schemas, versions, errors and trace context taught
traceparentparsing and the legal forwarding mutations. Here the new work is joining several processes' logs by those IDs, and the rule that the headers never carry sensitive data. - The network model is a seeded program: per-message delay, drop, duplicate, reorder and corrupt actions plus partition, restart and cancel, all from one retained seed.
- The Systems unit on deterministic network fault injection taught the harness shape. Here the new work is the RPC envelope logging plus the seeded schedule that the rollout matrix will reuse.
Common mistakes · 3
- Sorting cross-machine logs by timestamp to find causality. Skew and jumps reorder them; join on trace id and parent id and infer order from send and receive pairs.
- Using
randomwithout a seed for faults. An unseeded run cannot replay, so the failure is anecdote; retain the seed and the raw history with every run. - Resetting sequence numbers or timers carelessly. DSLabs search tests require finite, sequential numbering to exhaust the state space; ad hoc numbering explodes it.
Try it yourself
Closed-book, before checking anything
tracestate entry, then replay seed 7 through your faulty network and show the same drop, duplicate and reorder positions twice from the retained log.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Two logs show the server receiving before the client sent, by timestamps. What do you trust?Answer
The IDs, not the timestamps. Join on trace id and parent id; the send precedes the receive by causality, and the clock comparison is skew.
2.What must change in
traceparentat each hop, and what must not?AnswerSet a new parent id for the outgoing call, and change the sampled flag only if your sampling decision changed. Keep the trace id unless you deliberately restart the trace, which splits it.
3.A fault run fails once in ten tries. What do you keep to make it deterministic?Answer
The seed, the code version, the schedule of faults, and the raw message history. Rerun the same seed to replay the same orderings.
4.When should a proxy modify
tracestateorder?AnswerModified keys move to the left; unmodified pairs keep order. Deleting unknown keys breaks other vendors, so only remove for documented privacy or size reasons.
Practice
- Building Distributed Systems: TH-2 envelope logger and TH-5 chaos mode
TH-2 envelope logger with timestamps, then TH-5 chaos mode with random drops at /tracks/messenger/tasks/task-1-3-5-chaos-mode
Tasks are graded in the browser after login, so treat a pass as a drill and keep your seeded harness with retained histories as the evidence.
You're done when
One trace reconstructs across two processes by ID alone, and two runs of the same seed produce byte-identical fault histories.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 14 more in the section
- 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. - 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.
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.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. - 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.