~/networking/tcp-working-model.md
TCP: a working mental model
A compact model of reliable byte streams, acknowledgements, flow control, and congestion control.
TCP provides a reliable, ordered byte stream between two endpoints. It does not preserve application message boundaries: the receiver observes bytes, not the chunks passed to individual send calls.
The useful abstraction
Think of each direction as a numbered stream of bytes. The sender tracks bytes that have been sent but not yet acknowledged. The receiver acknowledges the next byte it expects.
sender receiver
| ------ bytes 0..999 --------> |
| <--------- ACK 1000 ---------- |
An acknowledgement of 1000 means that every byte through 999 arrived in order.
Reliability
Reliability is constructed from sequence numbers, acknowledgements, timers, and retransmission. Duplicate data can arrive, so the receiver must recognize and discard it without exposing duplicates to the application.
Two different limits
Flow control protects the receiver. Its advertised window describes how much data the receiving application and buffer can currently accept.
Congestion control protects the network. The congestion window estimates how much unacknowledged data the path can sustain. A sender is constrained by the smaller of these two windows.
Reliability is not a property of a packet. It emerges from protocol state maintained across many packets.
Questions to expand
- How do slow start and congestion avoidance differ?
- Why does TCP estimate round-trip time?
- What problem does selective acknowledgement solve?
- How do head-of-line blocking and QUIC relate?