Section 3 of 7 · Systems Foundations
Networks, Sockets & RPC Contracts
A network turns local calls into partial and ambiguous outcomes. This section builds byte-stream discipline, bounded retry behavior and an observable request contract before adding replicated state.
8 units 21 topics 0/8
Units
8 in this section
- 3.1 Network layers, addressing, routing and DNS explain3 h
- 3.2 TCP and UDP transport behavior explain · measure4 h
- 3.3 TLS and HTTP versions explain3 h
- 3.4 Sockets, partial reads and writes, and message framing implement5 h
- 3.5 RPC schemas, versions, errors and trace context explain · implement3 h
- 3.6 Deadlines, retries and idempotency across RPC derive · implement4 h
- 3.7 Connection shutdown, pools and latency decomposition explain · measure4 h
- 3.8 Deterministic network fault injection implement · measure3 h
Before moving on
Checkpoint
Pass partial, coalesced, oversized, malformed, timeout, duplicate, disconnect and restart cases against a versioned framed service. State exactly when a side effect is known, unknown, prevented or safely repeated.
Deliberately out of scope
Leave for later
- Raft and replicated protocol implementation
- Service meshes, QUIC internals and fleet routing
- Kernel-bypass or RDMA networking
Resources for this section
Shared by every unit above
- Beej's Guide to Network Programming - sockets to multiplexing 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 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.
- AlgoMaster Networks - pcap and concurrent server labs 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 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.
- Replicated Log and Stream Processor - protocol slice 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.
- Designing Data-Intensive Applications, 2nd edition - Chapter 5 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 Deadlines guide Read Overview, Deadlines on the Client and Deadline Propagation for absolute deadlines, remaining-time forwarding and clock-skew shielding.
- gRPC Status Codes Read the full status list, including
DEADLINE_EXCEEDED,UNAVAILABLEand the codes never generated by the library, for the error taxonomy. - W3C Trace Context Read Section 3.2 for the
traceparentformat and Sections 3.4 to 3.5 for the legaltraceparentandtracestatemutations when forwarding.
Apply the section
Mini-project · Versioned framed key-value service with deadlines and fault matrix (12 to 16 h)
Put the service slice on the network with a versioned framed protocol, request identity, deadlines and idempotent writes served through the bounded pool. Then prove the contract with a deterministic fault proxy and a full verdict matrix.
Steps
- Define the length-prefixed versioned frame in
kv/protocol.pyas a pure function over a byte buffer, and test splits at every offset, small reads, oversized and truncated inputs and newer-client compatibility. - Serve decoded requests through the
WorkerPoolwith immediate overload answers when full, echoidand continue the trace with a new parent, and reject unknown versions while ignoring unknown fields. - Propagate caller budgets as arrival-based deadlines on the monotonic clock, make writes idempotent by key with replay and rejection rules, and retry only retryable errors with jittered backoff inside the deadline.
- Write
kv/client.pywith client-generated request identity, a pool sized from target rate and hold time, per-request deadlines, and a test where a caller waiting for a connection gives up at its deadline. - Write a schedule-driven fault proxy that logs every action and replays byte-identical logs, then pass the full fault matrix with a verdict row per case and exactly-once effects under duplication and retry, leaving the restart row for the durability section.
- Capture one put with
tcpdumpor a container-attached capture, label the handshake, length prefix, payload bytes and close, and keep the capture with the write-up.
Deliverables
kv/protocol.py,kv/server.pyandkv/client.pywith framing, identity, deadline, idempotency, retry and pool tests.- The schedule-driven fault proxy with replayable logs and the full verdict matrix, with restart marked for durability.
- One labeled packet capture of a put with the handshake, frame and close identified.
Checks
- rubric · Self-grade with the rubric below
Rubric
| Criterion | Pass | Strong |
|---|---|---|
| Framing and identity | Split, oversized and truncated frame tests pass, responses echo identity, and unknown versions and fields behave. | A randomized split and payload property test backs the offset cases. |
| Deadlines and idempotency | Budgets shrink hop by hop on own clocks, expired work never starts, duplicates replay or wait, and mismatched bodies reject. | A forced queue-expiry test shows the client sees a deadline error rather than a late success. |
| Fault evidence | Every matrix case has a verdict row, replays give identical logs, and duplicated work applies once. | Each unknown outcome names the probe that would resolve it. |
Feeds into: Capstone service slice: framed RPC, identity, deadlines, retries and deterministic network faults. The matrix joins the dossier and restart passes once durable.