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.
Section 3 of 7 · 8 units · about 29 hours
By the end you can 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.
Units
- Network layers, addressing, routing and DNS3h
- TCP and UDP transport behavior4h
- TLS and HTTP versions3h
- Sockets, partial reads and writes, and message framing5h
- RPC schemas, versions, errors and trace context3h
- Deadlines, retries and idempotency across RPC4h
- Connection shutdown, pools and latency decomposition4h
- Deterministic network fault injection3h
Build it
Mini project · about 12 to 16 hours
Versioned framed key-value service with deadlines and fault matrix
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.
- 1Define 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. - 2Serve 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. - 3Propagate 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.
- 4Write
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. - 5Write 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.
- 6Capture 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.
What you hand in
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.
How to check it
- Self-grade with the rubric below
How it's graded
Framing and identity
Pass: Split, oversized and truncated frame tests pass, responses echo identity, and unknown versions and fields behave.
Great: A randomized split and payload property test backs the offset cases.
Deadlines and idempotency
Pass: Budgets shrink hop by hop on own clocks, expired work never starts, duplicates replay or wait, and mismatched bodies reject.
Great: A forced queue-expiry test shows the client sees a deadline error rather than a late success.
Fault evidence
Pass: Every matrix case has a verdict row, replays give identical logs, and duplicated work applies once.
Great: Each unknown outcome names the probe that would resolve it.
Resources
- Beej's Guide to Network Programming - sockets to multiplexingBrian Hall
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
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 labsAlgoMaster
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.
- Designing Data-Intensive Applications, 2nd edition - Chapter 5O'Reilly
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.
- MIT 6.5840 - RPC, threads and fault vocabularyMIT PDOS
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 sliceRoadmap-Final
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
Read Overview, Deadlines on the Client and Deadline Propagation for absolute deadlines, remaining-time forwarding and clock-skew shielding.
- gRPC Status CodesgRPC Authors
Read the full status list, including
DEADLINE_EXCEEDED,UNAVAILABLEand the codes never generated by the library, for the error taxonomy. - W3C Trace ContextW3C
Read Section 3.2 for the
traceparentformat and Sections 3.4 to 3.5 for the legaltraceparentandtracestatemutations when forwarding.