7 routes42 sections324 units

Unit 3.5 · about 3 h

253 / 324

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.

  • explain
  • implement

You can now

  • 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 taxonomy
  • Request IDs, correlation and end-to-end trace context

Study, in this order

5 steps

  1. Schemas and service dataflow
    Designing 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

    Depth · 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 structure
    MIT 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

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

  3. Schemas, status and evolution in gRPC
    AlgoMaster 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 list
    gRPC Status Codes

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

  5. Traceparent and tracestate
    W3C Trace Context

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

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.

Reproduce closed-book

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.

Traps

  • 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.

Practice

AlgoMaster: Audit Correlation ID Propagation

brokenHops and firstBrokenHop over receive-forward chains; regenerated IDs break the boundary rule

A later hop that preserves a regenerated ID is not itself broken; only the regenerating hop is.

AlgoMaster: Calculate Trace Span Exclusive Time

Exclusive time as duration minus the union of direct-child intervals; ties break by smaller ID

Subtract the union \([10,80)\), not the sum of overlapping children.

Self-test

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

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

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

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

Completion criterion

Stop 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.

Mark passed, then open 3.6 Only mark this when you can do it without notes.

Leads to

Comes after

Resources for this unit

  • AlgoMaster Networks - pcap and concurrent server labs
    AlgoMasterrequiredpractice
    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 vocabulary
    MIT PDOSsupporttheory
    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 5
    O'Reillyrequiredtheory
    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 Codes
    gRPC Authorsreferencereference
    Read the full status list, including DEADLINE_EXCEEDED, UNAVAILABLE and the codes never generated by the library, for the error taxonomy.
  • W3C Trace Context
    W3Creferencereference
    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 multiplexing
    Brian Hallprimarycourse
    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 path
    Brian Hallrequiredtheory
    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 slice
    Roadmap-Finalsupportproject
    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 guide
    gRPC Authorsreferencereference
    Read Overview, Deadlines on the Client and Deadline Propagation for absolute deadlines, remaining-time forwarding and clock-skew shielding.

Quick find

Search Michi

Type to search every route, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels