Unit 4 of 13 · about 3 hours · implement
Message size, allocation and decompression limits, and checksum boundaries
One uncapped length field lets a peer force a huge allocation. One unchecked hop lets a bit flip become a wrong applied effect.
You'll be able to
- Enforce frame, allocation and decompression caps that reject oversized input before allocating.
- Compute and verify checksums over defined byte ranges and state what each check cannot catch.
- Distinguish accidental-corruption detection from identity and authenticity guarantees.
Covers
Read
In this order, only the parts listed
0 of 2 done
- AlgoMaster checksums lessonAlgoMaster System Design - Selected Networking and API Problems
Sections 1 to 4 and 7: what a checksum can and cannot tell you; parity, additive checksums, CRC, cryptographic hashes, HMACs and signatures; end-to-end integrity
- Avro schema fingerprints and block checksumsProtocol Buffers and Avro - Unknown Fields and Schema Resolution
Single-object encoding: marker
C3 01, then the 8-byte little-endian CRC-64-AVRO fingerprint of the writer schema, which identifies the schema and does not check the payload; Object Container Files, Optional Codecs: each snappy block is followed by a 4-byte big-endian CRC32 of the uncompressed data
Focus on
- Check the length before allocating the body, and cap decompressed output independently of compressed input. A small compressed frame can expand by orders of magnitude.
- A checksum answers only whether these bytes match the expected bytes under this algorithm. It says nothing about who produced them or whether they are the latest.
- Cover the bytes that matter with the check you verify: header plus payload, or payload only, must be an explicit contract, and every hop must know which one it checks.
- Simple additive checksums such as the Internet checksum can miss reordered words and errors that cancel; CRCs catch burst errors and bit flips far better. Neither stops a deliberate change: that needs an HMAC or a signature.
Common mistakes · 3
- Allocating
lengthbytes before validatinglength. Validate against the cap first, then allocate, then read the body. - Using CRC where authenticity is needed. CRC catches accidental damage; it does not stop a forged message, which needs a keyed check.
- Checksumming the wrong range. A header-only check misses payload flips and a payload-only check misses a corrupted length; state the range in the contract.
Try it yourself
Closed-book, before checking anything
[0x4500, 0x003C, 0x1C46] gives 40573 and [0xFFFF, 0x0001] folds through 0x10000 to 0xFFFE. Then add a 1 MiB frame cap and a separate decompression cap to your framer.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Why fold the carry instead of truncating the sum to 16 bits?Answer
The Internet checksum uses ones-complement arithmetic, so overflow wraps around and is added back with carry folding before complementing, as the practice problem's
checksumsteps define.2.A 10-byte compressed frame claims a 100 MiB body. Which cap fires and when?Answer
The decompression cap fires during expansion, not the frame cap. The frame is small on the wire, so only a separate output cap stops the blowup, checked incrementally before the full output is held.
3.A CRC passes but the message is stale. Is the checksum wrong?Answer
No. The CRC only proves the bytes are intact. Freshness needs an incarnation, version or timestamp checked by the application.
4.Where does the Avro single-object header put the schema fingerprint, and why?Answer
After the
C3 01marker as 8 bytes, before the object. Readers that store records written under several schemas need the fingerprint to pick the right writer schema for resolution.
Practice
- Compute the Internet Checksum
Implement
checksum(words)with carry folding and complement; the judge checks the two worked cases including40573The expected
40573is correct, but the first example's explanation prints the sum as0x617Eand its complement as0x9E81(40577); the words sum to0x6182, whose complement0x9E7Dis40573. Then add frame and decompression caps with oversized and corrupt fixtures in your own harness.
You're done when
Your checksum matches both worked cases, your framer rejects an over-cap length before allocating and a corrupt payload on verify, and you can state the covered byte range.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 14 more in the section
- 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.
- 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.
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.
- 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. - 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.
- 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.