What is the difference between TCP flow control and congestion control?
Flow control stops a fast sender from overwhelming a slow receiver, using the receiver's advertised window. Congestion control stops senders from overwhelming the network in between, using a congestion window the sender maintains itself. The sender obeys the smaller of the two.
Explain it simply
Picture a water tank (the receiver) fed by a pipe through a city (the network). Flow control is the tank shouting "my level is nearly full, slow down". Congestion control is the sender noticing the city's pipes are jammed and easing off, even if the tank has room.
Example
rwnd = receiver window, sent in every ACK (receiver's free buffer)
cwnd = congestion window, calculated by the sender from loss and delay
bytes allowed in flight = min(rwnd, cwnd)
rwnd = 64 KB, cwnd = 20 KB -> sender may have 20 KB unacknowledged
rwnd = 8 KB, cwnd = 50 KB -> sender may have 8 KB unacknowledgedIf the receiving app reads slowly, its buffer fills and it advertises a window of 0, so the sender pauses and probes occasionally. That is flow control. If packets are being dropped at a congested router, the sender cuts cwnd, even though the receiver is perfectly happy. That is congestion control.
The receiver tells the sender about its own problem. The network never tells TCP directly (apart from optional ECN marks); TCP infers congestion from lost packets or growing delay.
What to say in the interview
"Flow control is end to end and protects the receiver, driven by the receive window in ACKs. Congestion control protects the network, driven by the sender's congestion window and inferred from loss. The sender's limit on unacknowledged data is the minimum of both windows."
Common mistakes
- Using the two terms as synonyms.