ConceptDifficulty: Intermediate2 min

Flow Control: The Receiver's Window

A receiver advertises how much it can take, so a fast sender cannot overrun a slow reader.

Flow control stops a sender from sending more data than the receiver has room to hold. Every segment the receiver sends back carries a window, the number of bytes it can still accept, and the sender never has more unacknowledged data in flight than that window allows. When the program on the receiving side reads slowly, its buffer fills, the window shrinks, and the sender slows down to match.

Think of a reader taking pages from someone who writes faster, and saying "I have room for three more pages" each time they hand one back. The writer never piles up more than that.

A 4,000-byte receive buffer filling and emptying, with the window advertised each time

InputA receive buffer of 4,000 bytes, shown as four slots of 1,000

  1. Empty buffer

    1. free
    2. free
    3. free
    4. free

    The receiver advertises a window of 4,000.

  2. 1,000 bytes arrive, the program has not read

    1. heldfilled
    2. free
    3. free
    4. free

    Window 3,000.

  3. 3,000 more arrive

    1. held
    2. held
    3. held
    4. heldfull

    Window 0. The sender must stop and wait.

  4. The program reads 3,000 bytes

    1. held
    2. freefreed
    3. free
    4. free

    Window 3,000. The receiver says so, and the sender resumes.

ResultThe sender's limit follows how fast the receiving program reads, not how fast the network is.

A window of zero pauses the sender completely. It then sends small probes from time to time, so it notices when the window opens again even if the update that announces it is lost.

The window field in the header is 16 bits, which would cap it at 64 KB, far too small for a fast connection across a continent. A window scale option, agreed during the handshake, multiplies it, so modern windows reach megabytes.

Flow control protects only the receiver. It knows how much room the receiving program has and nothing about the network in between, which may be far slower than either end. Protecting the network is a separate mechanism, congestion control.

A shrinking window is a useful sign when diagnosing a slow transfer. If a packet capture shows the receiver advertising a window near zero, the network is not the bottleneck: the program at the receiving end is not reading fast enough, perhaps because it is busy writing to a slow disk.

So when a sender is waiting on a full window, look at the receiver, not the path between them.