Unit 2 of 13 · about 4 hours · explain, implement
Schema fields, defaults, unknown-field preservation and wire compatibility
Rollouts mix old and new binaries for days. A field added carelessly becomes data loss or a privacy leak on the mixed paths.
You'll be able to
- Explain proto3 defaults, field-number rules and unknown-field retention, and Avro reader-writer resolution.
- Build a four-version compatibility table and wire fixtures that prove each claim.
- State which changes are safe, which need rollout order, and which are never safe.
Covers
Read
In this order, only the parts listed
0 of 3 done
- DDIA 2e Chapter 5: Avro, Protobuf and schema meritsDDIA 2e - Chapter 5 Encoding and Evolution
Chapter 5, Protocol Buffers (pp. 169-172) with Figure 5-3, Avro (pp. 172-177) with Figures 5-4 to 5-6 on writer and reader schemas, and The Merits of Schemas (p. 177)
- Proto3 updating rules and unknown fieldsProtocol Buffers and Avro - Unknown Fields and Schema Resolution
Updating A Message Type: wire-safe additions, reserved numbers and names, never reuse a number; Unknown Fields: binary parse preserves unknown fields but JSON and text-format round trips lose them
- Avro 1.12.0 schema resolutionProtocol Buffers and Avro - Unknown Fields and Schema Resolution
Schema Resolution: readers ignore writer-only fields, fill reader-only fields from defaults, int promotes to long, float and double, string to bytes and back; aliases map renamed names
Focus on
- The Systems unit on RPC schemas, versions, errors and trace context taught field identity and proto3 presence. Here the new work is what survives a hop between versions: unknown fields, Avro resolution and the four-version fixtures.
- Reserving a deleted number and name is the change, not tidying. Reuse makes old bytes decode under a new meaning.
- Avro carries no field identifiers on the wire, so reader and writer schemas resolve by name and defaults. Protobuf carries tags, so unknown fields can survive a binary proxy hop.
- JSON and text-format conversions are lossy hops for unknown fields even when binary hops preserve them.
Common mistakes · 3
- Treating a default value as proof the sender set the field. An absent field also reads as the default, so defaults cannot carry I was explicitly cleared.
- Renumbering fields for neatness. Renumbering deletes and re-adds every field involved and breaks stored data.
- Proxying unknown fields through JSON for debugging and assuming they survive. Binary parsing and serialization and message-level copies such as
CopyFromandMergeFromkeep them; JSON output and field-by-field copies drop them.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.An old binary reads new data with one added field. What happens in Protobuf and in Avro?Answer
Protobuf keeps the extra field as unknown bytes and ignores it on read, preserving it on binary reserialization. Avro ignores the writer-only field during resolution, but only if the reader has the writer's schema to resolve against.
2.A field is deleted and its number reused for a new string field. What breaks?Answer
Old bytes for that number are decoded under the new definition. The proto3 guide lists the outcomes: a parse error at best, otherwise leaked personal data or silent corruption. Reserve the number and the name instead.
3.When is widening int to long safe in Avro, and what is the rollout condition?Answer
A reader whose schema says
longcan read data written asint, because int promotes to long. The reverse does not resolve: a reader still onintfails on data written with alongschema, whatever the values. So deploy thelongreader schema everywhere first, then switch writers.4.Why does
optionalmatter for a boolean that switches behavior when false?AnswerWithout presence, unset and explicitly false both read as false, so a default rollout silently enables the behavior. Presence separates the two states.
Practice
- Building Distributed Systems: TH-1 typed schema
TH-1 typed schema: wrap raw messages in validated classes with explicit fields and serialization methods
Tasks are graded in the browser after login, so treat a pass as a drill and keep your four-version binary fixtures and compatibility table as the evidence.
You're done when
Your table predicts all four version crossings correctly and your fixtures show unknown-field survival on binary paths and loss on JSON paths.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 14 more in the 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.
Also in this 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.
- 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.
- 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.