Lesson 04: Congestion Control

Protecting the Internet

Flow control protects the receiver. But what protects the network itself? If millions of machines start blasting packets at their maximum bandwidth, the routers between them will run out of buffer space, dropping packets en masse. This causes machines to retransmit, which creates more traffic, leading to total "Congestion Collapse."

To prevent this, TCP uses a Congestion Window (cwnd). A sender can only send the minimum of the receiver's window (rwnd) and the congestion window (cwnd).

Slow Start & AIMD

Because the sender doesn't know the capacity of the network, it has to probe for it. It starts with a very small cwnd (historically 1 packet, today usually 10) in a phase called Slow Start. For every ACK it receives, it increases cwnd by 1 packet, effectively doubling the window every round-trip. It's exponential growth.

Once it hits a threshold or experiences packet loss, it shifts to Congestion Avoidance. Here, it uses AIMD (Additive Increase, Multiplicative Decrease): it grows cwnd by just 1 packet per round-trip (additive increase), but if a packet drops, it halves the cwnd instantly (multiplicative decrease).

The TCP Sawtooth Simulator

Click "Progress Round Trip" to watch cwnd grow. It begins in Slow Start (exponential) and then switches to Congestion Avoidance (linear) after passing the threshold. Click "Simulate Packet Loss" to trigger the multiplicative decrease.

cwnd time (RTTs) ssthresh = 32 State: Slow Start cwnd = 2

If you keep advancing time and dropping packets, you'll see a distinct pattern: a slow climb followed by a sharp drop. This pattern is famously known as the TCP Sawtooth. It means your TCP connection is constantly probing the network, pushing just a little bit harder until the network breaks, backing off, and then pushing again.

Why webpages take a moment to "speed up": When you download a large file, the speed doesn't instantly jump to your 1Gbps maximum. Because of Slow Start, it takes multiple round-trips for the cwnd to grow large enough to saturate the pipe. If you are communicating with a server 100ms away, it might take a full second of back-and-forth just to open the window enough to achieve high bandwidth.

Check yourself

1. During the "Slow Start" phase, how fast does the congestion window (cwnd) grow?

Despite the name "Slow Start", it is actually the most aggressive growth phase of TCP. The window doubles every round-trip to rapidly discover the network's maximum capacity.

2. Why does the TCP throughput graph look like a "Sawtooth"?

The AIMD (Additive Increase, Multiplicative Decrease) algorithm naturally produces the sawtooth shape: probing slowly until it hits the ceiling, backing off, and trying again.