TCP Flow Control
The sliding window that stops a fast sender from drowning a slow receiver
A fast server can produce data far quicker than a slow client can consume it. Flow control is TCP’s mechanism to keep the sender from overflowing the receiver’s buffer — using a value called the window.
Careful: flow control protects the receiver, not the network. Protecting the network is congestion control, the next chapter.
The problem
The receiver has a limited buffer where incoming data waits to be read by the application. If the sender pushes data faster than the app reads it, that buffer fills up and overflows — and data is lost. Flow control prevents this.
The receive window (rwnd)
The receiver tracks how much free space is left in its buffer and calls it the receive window (rwnd). This number is the maximum amount of unacknowledged data the sender is allowed to have in flight at once.
Advertised in every ACK
The receiver advertises its current window in the Window field of every segment it sends back. So with each ACK the sender learns exactly how much more it may send. It must never exceed the advertised window.
The sliding window
Picture the byte stream divided into: bytes sent and acknowledged, bytes sent but not yet acknowledged (in flight), bytes that may be sent now, and bytes that must wait. As ACKs arrive, the window slides to the right, letting new data be sent. Hence "sliding window".
Window scaling
The window field is only 16 bits, capping it at 64 KB — too small for modern fast, long-distance links. The window scale option multiplies the window by a factor negotiated in the handshake, allowing much larger windows so fast links can stay full.
Zero window = pause
If the receiver’s buffer is completely full, it advertises Window = 0, telling the sender to stop. The sender periodically sends tiny "window probes" to ask if space has opened up, and resumes once the receiver advertises a non-zero window again.
Flow ≠ congestion
Do not confuse them: Flow control protects the RECEIVER (its buffer). Congestion control protects the NETWORK (the links in between). Same goal of smooth delivery, different bottleneck — congestion control is next.