Unit 5 of 8 · about 3 hours · explain, implement

RPC schemas, versions, errors and trace context

Schemas and status codes are the contract clients program against; trace context is how you debug it. It builds on the Programming OpenTelemetry unit (programming/concurrency-profiling-operations/logs-metrics-traces), which covered spans and bounded labels; here the wire format is the mechanism.

You'll be able to

  • Define an RPC schema with field identity, presence rules and safe evolution (add, never reuse).
  • Separate transport status from RPC status when reading errors.
  • Propagate W3C trace context across hops and keep correlation IDs intact.

Covers

Serialization, schemas, protocol versions and error taxonomyRequest IDs, correlation and end-to-end trace context
1

Read

In this order, only the parts listed

0 of 5 done

  1. Schemas and service dataflowDesigning Data-Intensive Applications, 2nd edition - Chapter 5

    Chapter 5, Formats for Encoding Data (printed pp. 163 to 177) for schema merits and compatibility; Dataflow Through Services: REST and RPC (printed pp. 180 to 186) for version coexistence

    Read the two sections only, not the whole chapter. Follow the idempotence pointer to Chapter 12 later, in the streams section.

  2. MIT 6.5840 Lecture 2: RPC structureMIT 6.5840 - RPC, threads and fault vocabulary

    The Remote Procedure Call (RPC) section to the end: the message diagram, the kv.go example and the RPC failure questions

    Read the RPC half only; the threading and crawler half is assumed from the concurrency stage.

  3. Schemas, status and evolution in gRPCAlgoMaster Networks - pcap and concurrent server labs

    Protocol Buffers as a Schema; Presence and Default Values; Evolving a Protobuf Contract Safely; The Five-Byte gRPC Message Prefix; HTTP Status Is Not RPC Status; gRPC Status Codes

  4. The status listgRPC Status Codes

    Full list of Status codes, including DEADLINE_EXCEEDED, UNAVAILABLE, and the codes never generated by the library

  5. Traceparent and tracestateW3C Trace Context

    Section 3.2 (traceparent format and examples); Sections 3.4 to 3.5 (legal mutations when forwarding)

2

Focus on

  • Wire identity is the field number, not the name. In the binary encoding, renaming tag 2 is compatible; changing 2 to 4 deletes a field and creates another. JSON mappings use names, so a rename breaks them.
  • proto3 scalars conflate absent with default. Use optional, oneof or message fields when the distinction changes behavior.
  • HTTP 200 with a nonzero grpc-status is an RPC failure. Monitors that check only HTTP status report success while every call fails.
  • Forwarding a trace means sending traceparent with a new parent-id and preserving tracestate order; a hop that regenerates the trace-id splits the trace.
Common mistakes · 3
  • Reusing a deleted field number for a new type. Old binaries parse the new bytes as the old type; use a fresh number.
  • Hiding errors inside OK responses. Clients, retry policies and metrics can only reason about errors carried in status.
  • Putting secrets or high-cardinality values into trace context. traceparent and tracestate propagate to every downstream service, and the spec forbids personally identifying data there.
3

Try it yourself

Closed-book, before checking anything

Closed-book, parse 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01 into version 00, 16-byte trace-id, 8-byte parent-id and sampled flag, and state the legal forwarding mutations (new parent-id, optional sampled change, restart, downgrade). Then add a request-id field to your framed protocol and show it echoed unchanged in the response.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Field 2 changes from string to int32 with the same number. Wire-compatible?Answer

    No. A string travels length-delimited and an int32 as a varint, so old readers cannot decode it as their string; most runtimes keep it as an unknown field and the value is lost to them. Add a new field number instead.

  2. 2.A proxy returns HTTP 200 for an RPC that failed with grpc-status 14. What should the dashboard show?Answer

    An RPC failure with UNAVAILABLE. Transport success and RPC outcome are separate channels.

  3. 3.A service forwards traceparent byte-identical and appends its tracestate entry. Correct?Answer

    No. It must set parent-id to its own current operation ID; byte-identical forwarding claims the downstream work is the same span. New tracestate entries go first, not last.

  4. 4.Why must the server application stop its own work when gRPC signals cancellation for deadline?Answer

    The runtime only signals; spawned database calls and child RPCs keep running and consuming resources until the application stops them.

5

Practice

You're done when

You evolve a schema without breaking an old reader, classify an RPC failure by its status code, and trace one request across two hops without dropping its ID.

Only when you can do this without notes.

Leads to

Notes

Resources · 5 for this unit, 4 more in the section
  • AlgoMaster Networks - pcap and concurrent server labsAlgoMaster · required

    Use Reading a Packet Capture: A Real Bug and Building a Concurrent TCP Echo Server after the Beej implementation. Reproduce one packet-level observation and one admission, deadline or shutdown behavior in your independently written service.

  • MIT 6.5840 - RPC, threads and fault vocabularyMIT PDOS · support

    Read the introductory RPC and threads material plus the lab guidance. Use it to enumerate timeout ambiguity and duplicate effects. Stop before Raft and the full lab sequence.

  • Designing Data-Intensive Applications, 2nd edition - Chapter 5O'Reilly · required

    Read Formats for Encoding Data (printed pp. 163 to 177) for schema merits and compatibility, and Dataflow Through Services: REST and RPC (printed pp. 180 to 186) for service dataflow, version coexistence and the idempotence pointer.

  • gRPC Status CodesgRPC Authors · reference

    Read the full status list, including DEADLINE_EXCEEDED, UNAVAILABLE and the codes never generated by the library, for the error taxonomy.

  • W3C Trace ContextW3C · reference

    Read Section 3.2 for the traceparent format and Sections 3.4 to 3.5 for the legal traceparent and tracestate mutations when forwarding.

Also in this section

  • Beej's Guide to Network Programming - sockets to multiplexingBrian Hall · primary

    Read What is a socket?, IP addresses and data structures, Client-server background, System calls or bust, Client-server examples, Slightly advanced techniques and sendall. Build the simple TCP pair first, then replace delimiter assumptions with a bounded length-prefixed protocol.

  • Beej's Guide to Network Concepts - TCP and UDP pathBrian Hall · required

    Read the OS and sockets, protocol layering, IP, UDP and TCP chapters alongside packet captures from your own client and server. Use it to explain transport behavior rather than memorize layer names.

  • Replicated Log and Stream Processor - protocol sliceRoadmap-Final · support

    Use only the protocol requirements, deterministic network fault matrix and delivery-contract questions. Build the single-node framed service now; keep replication and consensus for the later project.

  • gRPC Deadlines guidegRPC Authors · reference

    Read Overview, Deadlines on the Client and Deadline Propagation for absolute deadlines, remaining-time forwarding and clock-skew shielding.