No history yet

Transport Layer Flow Control

Setting Up the Conversation

Before two devices can reliably exchange data using TCP, they need to establish a connection. This isn't like flipping a switch; it's a careful, three-step negotiation known as the three-way handshake. It ensures both sides are ready to send and receive data, and agree on starting points for tracking that data.

  1. SYN: The client sends a packet with the SYN (synchronize) flag set. This packet includes an initial Sequence Number (ISN). Think of this as, "Hi, I'd like to start a conversation. I'm starting my numbering at X."
  2. SYN-ACK: The server receives the SYN packet. It responds with its own packet that has both the SYN and ACK (acknowledgment) flags set. This packet contains the server's own ISN and acknowledges the client's number. This is like saying, "I hear you! I'll start my numbering at Y, and I'm ready for your number X+1."
  3. ACK: The client receives the SYN-ACK and sends a final ACK packet back to the server, acknowledging the server's sequence number. The message is, "Got it! Let's talk." At this point, the connection is established, and data transfer can begin.

Ending the conversation is just as deliberate. It typically involves a four-way handshake, where each side sends a FIN (finish) packet to signal they are done sending data and receives an ACK in return. This ensures no data is cut off prematurely.

Managing the Flow

Once a connection is live, the next challenge is managing the rate of data transfer. A powerful server can easily overwhelm a smartphone on a slow network. This is where flow control comes in. TCP uses a mechanism called the sliding window to solve this problem.

Imagine the receiver has a buffer, like a mailbox, to hold incoming data before the application can process it. The receiver tells the sender the size of this buffer—how much free space it has. This advertised size is the "receive window."

The sender can then send an amount of data up to the size of that window without waiting for an acknowledgment for every single packet. As the receiver processes data and frees up buffer space, it sends acknowledgments that include the updated window size. This window "slides" forward as data is sent and acknowledged, creating a continuous and efficient flow without overwhelming the receiver.

Flow control is about protecting the receiver from being flooded by the sender. It's an end-to-end mechanism that has nothing to do with network congestion.

Modern networks are fast, and the original window size limit (65,535 bytes) can become a bottleneck. To deal with this, the TCP window scale option was introduced. It's negotiated during the initial three-way handshake and allows the window size to be multiplied by a scale factor, enabling much larger window sizes for high-bandwidth, high-latency connections.

Dealing with Traffic Jams

Flow control handles the receiver's capacity, but what about the network's capacity? A network can become congested just like a highway during rush hour. TCP has a separate set of mechanisms for congestion control to avoid overwhelming the routers and switches in between.

TCP assumes that packet loss is caused by network congestion. When a connection starts, it doesn't know the available bandwidth, so it begins cautiously in a phase called Slow Start. It sends a small number of packets and doubles that number for every acknowledgment received. This creates an exponential growth in the sending rate.

This rapid growth can't last forever. Once the sending rate reaches a certain threshold (or a packet is lost), TCP switches to Congestion Avoidance. In this phase, it increases the sending rate much more slowly, typically by one packet for each round-trip time. This probes for available bandwidth more gently.

If a sender sends several packets and receives duplicate acknowledgments for the same packet, it's a strong hint that the next packet in the sequence was lost. Instead of waiting for a full timeout, TCP can trigger a Fast Retransmit, resending the presumed lost packet immediately. This helps maintain the flow of data much more effectively than waiting for a timer to expire.

Efficient Acknowledgments

The simplest form of acknowledgment in TCP is cumulative. When the receiver sends an ACK with number N, it's confirming it has received all data up to byte N-1 without any gaps.

This works well, but what if multiple packets are lost within a single window? For example, packets 3, 5, and 6 are lost. The receiver gets packet 4, but it can only acknowledge up to packet 2. The sender will eventually time out and retransmit everything from packet 3 onward, even though packets 4, 7, and 8 were received correctly. This is inefficient.

To solve this, most modern TCP implementations use Selective Acknowledgment (SACK). With SACK, the receiver can acknowledge non-contiguous blocks of data. In our example, the receiver can send an ACK for packet 2, but also include SACK information telling the sender, "I also have the data from packets 4, 7, and 8." This allows the sender to retransmit only the specific packets that were lost (3, 5, and 6), saving a significant amount of bandwidth.

The Speedy Alternative

For some applications, all this reliability is overkill. Think about a live video stream or an online game. If a single frame of video or a positional update is lost, it's better to just skip it and move on to the next one. Waiting to retransmit old data would just cause lag and stuttering.

This is where the User Datagram Protocol (UDP) comes in. UDP is a connectionless, "fire-and-forget" protocol. It provides no handshakes, no acknowledgments, no flow control, and no error recovery. It simply wraps data in a packet and sends it.

The trade-off is clear: UDP sacrifices reliability for speed and low overhead. It's the perfect choice for real-time applications where timeliness is more important than perfect data integrity. It's up to the application itself to handle any necessary error checking if needed.

Two main protocols: TCP (Transmission Control Protocol): Reliable delivery (like registered mail) UDP (User Datagram Protocol): Fast delivery (like regular mail)

Now, let's test your understanding of these transport layer concepts.

Quiz Questions 1/6

What is the correct sequence of flags exchanged during a successful TCP three-way handshake to establish a connection?

Quiz Questions 2/6

What is the primary purpose of TCP's 'sliding window' mechanism?

Understanding how TCP and UDP manage data flow is key to diagnosing network performance issues and building efficient applications. TCP provides the robust, reliable foundation for most web traffic, while UDP offers the raw speed needed for real-time communication.