Unit 2 of 8 · about 4 hours · explain, measure
TCP and UDP transport behavior
Sockets expose streams, not messages. Misreading TCP as a message protocol causes every framing bug in the next unit, and confusing flow control with congestion control misdirects tuning.
You'll be able to
- Explain the TCP service contract: reliable ordered duplicate-suppressed byte stream, setup cost, and what an
ACKdoes not promise. - Contrast UDP datagrams with TCP streams and choose between them from loss, ordering and latency needs.
- Read zero-window, retransmission and congestion evidence in a capture and name the limiting mechanism.
Covers
Read
In this order, only the parts listed
0 of 6 done
- TCP versus UDP contractsAlgoMaster Networks - pcap and concurrent server labs
TCP's Service Contract (reliable, ordered, duplicate suppression, byte stream); UDP's Service Contract; Message Size Matters
- The TCP three-way handshakeAlgoMaster Networks - pcap and concurrent server labs
Step 1 through Step 3; Sequence Number Arithmetic; Why Three Messages Are Necessary; Listening Queues and Server Load
- Reliability and flow controlAlgoMaster Networks - pcap and concurrent server labs
Reliability Is Defined Over Bytes; An ACK Is Not an Application Receipt; Gaps and Duplicate ACKs; Retransmission Timeout; then Flow Control and the Sliding Window: Receive Buffers and Application Reads, Zero Window, Diagnosing a Flow-Control Stall
Use https://algomaster.io/learn/computer-networks/flow-control-sliding-window for the flow-control sections.
- TCP and UDP path in Beej's Network ConceptsBeej's Guide to Network Concepts - TCP and UDP path
Chapter 14, TCP (Sections 14.4.1, 14.4.2 and 14.6); Chapter 15, UDP (Sections 15.4, 15.6 and 15.7)
- A real zero-window stallAlgoMaster Networks - pcap and concurrent server labs
Turn the Stream into a Timeline; Inspect the Edges of the Gap (zero-window evidence); the host-correlation conclusion
Follow the phase method and the window evidence. The audit-pipe root cause is one example of host correlation, not a pattern to memorize.
- Congestion control vocabulary (optional topic)AlgoMaster Networks - pcap and concurrent server labs
Flow Control and Congestion Control Solve Different Problems; Slow Start; Congestion Avoidance and AIMD
Vocabulary only for the optional topic. No measurement required; stop before the variant comparison.
Focus on
- TCP numbers bytes, not messages. The
ACKadvances over the contiguous prefix; a gap stalls acknowledgment even when later bytes arrived. - An
ACKmeans the peer kernel holds the bytes. It does not mean the application read or acted on them. - Flow control (receiver window) and congestion control (sender network estimate) are independent limits; the sender obeys the smaller.
- UDP preserves message boundaries and promises nothing else. Loss, duplication and reordering are normal and must be handled above it.
Common mistakes · 3
- Calling a retransmission proof of packet loss. Delayed ACKs, reordering and spurious timeouts cause retransmissions on healthy paths.
- Expecting
closeto deliver pending application work. A gracefulFINends the byte stream; it says nothing about processed requests. - Treating UDP as TCP without acknowledgments. Without sequence numbers and reassembly above it, duplicates and reordering reach the application.
Try it yourself
Closed-book, before checking anything
create_connection plus close calls after 10 warm-up ones; then time 200 round trips of a 4-byte length-prefixed echo (TCP_NODELAY, 20 warm-up) at 64 bytes and 64 KiB. Pinned to two performance cores with taskset -c 2,4 on an i9-12900K with Linux 7.0, three runs gave connect plus close medians of 12 to 16 us, a 64 B echo p50 of about 9 us and a 64 KiB p50 of about 29 us; unpinned runs that landed on efficiency cores were up to about twice as slow. Record yours with the same setup and say which cores ran it.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Segments and arrived. Which byte does the receiver ACK next?Answer
Byte 3. The ACK covers only the contiguous prefix from 0; bytes 5 and 6 wait behind the gap at 3 and 4.
2.The client advertised a zero window for five seconds, then the transfer resumed with no retransmissions. Where was the stall?Answer
At the receiving endpoint: its buffer stayed full because the application stopped reading. The network and server were waiting on window updates.
3.Why does a fresh TCP connection cost at least one round trip before data flows?Answer
SYN,SYN-ACKandACKmust synchronize sequence numbers and open state on both ends; data normally starts after the exchange.4.Two identical datagrams arrive over UDP. Did the network duplicate one, or did the sender retransmit?Answer
UDP alone cannot tell. Both look identical; only an application sequence number distinguishes a duplicate from a retry.
Practice
- AlgoMaster: Reassemble TCP Segments
nextExpectedover out-of-order overlapping[seq, length]intervals under the contiguous-prefix ruleThe gap example (
[[0,3],[5,2]]returns3) is theACKrule in code; overlapping intervals must not double-count.
You're done when
You classify a stall as receiver-window, loss-recovery or endpoint silence from window and ACK evidence, and your reassembler returns 3 and 5 on the two worked examples.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 7 more in the section
- 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.
- 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.
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.
- 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.
- 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.
- 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 Deadlines guidegRPC Authors · reference
Read Overview, Deadlines on the Client and Deadline Propagation for absolute deadlines, remaining-time forwarding and clock-skew shielding.
- gRPC Status CodesgRPC Authors · reference
Read the full status list, including
DEADLINE_EXCEEDED,UNAVAILABLEand the codes never generated by the library, for the error taxonomy. - W3C Trace ContextW3C · reference
Read Section 3.2 for the
traceparentformat and Sections 3.4 to 3.5 for the legaltraceparentandtracestatemutations when forwarding.