TCP Flow Control: Sliding Window
What You'll Learn
You'll learn how TCP's sliding window mechanism allows a receiver to control the rate of data transmission and prevent being overwhelmed by a fast sender.
The Core Problem
Even though TCP provides reliable delivery through retransmissions, there's another challenge: the sender might be capable of transmitting data much faster than the receiver can process it. Without a control mechanism, the receiver's buffer could overflow, causing data loss.
How the Sliding Window Works
The receiver advertises a window size in every TCP segment it sends back to the sender. This window size tells the sender: "I have this many bytes of free buffer space available right now."
The sender must respect this limit — it can only send up to the advertised window size worth of unacknowledged data. As the receiver processes data and frees up buffer space, it updates the window size in its acknowledgment segments.
A Simple Analogy
Imagine you're tossing balls to a friend who's catching them and placing them in a basket. Your friend holds up fingers to show how many empty slots remain in the basket. If they show three fingers, you can toss up to three more balls. Once they place balls elsewhere and free up space, they'll signal you can send more.
Dynamic Adjustment
The window "slides" forward as:
- The receiver acknowledges data (confirming it was received and processed)
- Buffer space becomes available
- The receiver advertises a new, potentially larger window
If the receiver's buffer fills up, it can advertise a window size of zero, temporarily pausing transmission until space becomes available.
Key Takeaway: TCP flow control uses a sliding window where the receiver advertises available buffer space, ensuring the sender never transmits faster than the receiver can handle.