All notes
Networking The Transport Layer

TCP Congestion Control

  • As seen in a previous note, TCP provides a reliable transport service between two processes running of different hosts (e.g. two different laptops)
  • Another key component is its congestion control mechanism.

Classic End-to-End TCP Congestion Control

  • This approach taken by TCP1 is to have each sender limit the rate at which it sends traffic into its connection as a function of perceived network connection.
    • In other words, if a TCP sender believes there’s little congestion on the path between itself and the destination, then the TCP sender increases its snd rate. If it thinks there is congestions along the path, the sender reduces its send rate.
  • But this raises three questions
    1. How does a TCP sender limit the rate at which it sends traffic into its connection?
    2. How does a TCP sender perceive there’s congestion between itself and the destination?
    3. What algorithm should the sender use to change its send rate as a result of this congestion?

1) How does a TCP sender limit the rate at which it sends traffic into its connection?

  • Each side of a TCP connection consists of a receive buffer, a send buffer, and several variables (e.g. rwnd) (see more here).
  • To prevent network collapse, “Classic” TCP forces senders to obey a dynamic speed limit known as the congestion window (cwnd) – this is an additional variable included as part of the connection.
    • So the congestion window imposes a restraint on the rate at which a TCP sender can send traffic into the network.
  • The point is, a sender is constantly restricted by two different bottlenecks, and it must always obey which is stricter
    • rwnd (Receive Window): How much data the receiving computer can handle before its memory overflows.
    • cwnd (Congestion Window): How much data the network itself can handle before routers get congested.
  • So the amount of data “in flight” (sent out but not yet acknowledged) can never exceed the smaller of these two numbers.
    • To know how much data is ‘in flight’, it looks at the LastByteSent (the sequence number of the last byte of data the sender shipped into the network) and the LastByteAcked (the sequence number of the last byte the receiver got and acknowledged). By subtracting them you get the total number of data currently floating out on the network.
LastByteSent – LastByteAcked <= min{cwnd,rwnd}
TCP Speed Limit
TCP Speed Limit
  • To focus purely on network congestion, let’s assume the receiving computer has unlimited memory (i.e.we ignore the rwnd constraint), leaving cwnd as the sole speed limit.
  • The cwnd then dictates exactly how many bytes the sender can push into the network during one Round Trip Time (RTT)
    • If you send cwnd bytes, you must pause and wait for the acknowledgment before sending the next batch.
  • Therefore, the actual speed of the connection is the window size divided by the round-trip time: cwnd/RTT bytes per second.
    • I.e. mathematically, speed is just amount divided by time. If your batch size is cwnd and it takes one RTT to complete a round trip, your transmission speed is literally cwnd / RTT bytes per second.
  • So, by adjusting the value of cwnd, the sender can therefore adjust the rate at which it sends data into its connection.
Analogy
  • Imagine you manage a delivery business, but you only own 5 delivery vans (cwnd = 5).
    • You can send exactly 5 vans out onto the road at once (data in flight).
    • You cannot send another package until one of the original 5 vans returns to the warehouse empty (the acknowledgment).
    • If you want to increase your total delivery speed, your only option is to buy more vans (increase cwnd).
  • By simply adjusting this one variable up or down based on network conditions, a TCP sender smoothly throttles its transmission rate without needing to know exactly what the routers in the middle are doing.

2) How does a TCP sender perceive there’s congestion between itself and the destination?

  • TCP doesn’t have a direct line of communication with routers, so it can’t receive a messaging saying the network is getting crowded.
  • Instead, a “Classic” TCP sender has to act like a detective, figuring out there’s a traffic jam by looking for clues. Its main clue is called a loss event.
  • Basically, when router buffers overflow and packets get dropped, the sender discovers the problem through one of two triggers:
    • A timeout: the sender waits and waits for an acknowledgment, but none arrives before the timer runs out.
    • Three duplicate ACKs: the receiver keeps sending the exact same acknowledgment number multiple times (e.g. getting 3 separate messages saying “I’m still waiting for packet #5”), which is a clear giveaway that packet #5 was lost in transit.
  • When either of these happens, classic TCP assumes the worst: the path is congested, and packets are dropping because the network is overloaded.
  • Newer flavours of TCP, however, don’t wait for packets to drop.
    • They look at subtle warning signs – like a sudden spike in Round Trip Time (RTT) – to spot a traffic jam building up and slow down before data is lost.

3) How should an individual TCP sender determine the rate at which it should send?

Congestion Free Network

  • When no loss events occur, incoming acknowledgments (ACKs) tell the sender that packets are successfully reaching their destination.
  • TCP uses these incoming ACKs as a signal to increase its congestion window (cwnd), which safely speeds up transmission.
    • If ACKs arrive slowly (due to high delay or low bandwidth), cwnd increases slowly
    • If ACKs arrive quickly, cwnd grows faster.
  • Because the rate of incoming ACKs directly paces and triggers the growth of the window, TCP is considered self-clocking – it naturally adjusts its speed based on the rhythm of the network traffic flowing back to it.
  • Because there is no central traffic controller telling computers how fast to go, TCP uses a clever, decentralised strategy based on three core rules and three main tools.
  • The three guiding principles of TCP:
    1. ACKs mean “speed up”: when an acknowledgment arrives safely, it means the network is healthy and delivering your data. This is your cue to increase your speed.
    2. Loss means “slow down”: if a packet gets dropped (signalled by a timeout or duplicate ACKs), it means you’ve hit a traffic jam. You must cut your speed back.
    3. Bandwidth probing: TCP doesn’t know the network’s exact capacity, so it constantly tests the limits. It speeds up until it gets a “no” (a packet loss), backs off a bit, and then starts creeping up again.
  • To put these principles into action, the classic TCP algorithm uses three mechanical components:
    1. Slow start
    2. Congestion avoidance
    3. Fast recovery

Slow Start

  • Despite its name, Slow Start is actually a phase where TCP tries to find available bandwidth as fast as possible by rapidly increasing its speed.
  • When a TCP connection first opens, the congestion window (cwnd) is set to a tiny size of 1 MSS (Maximum Segment Size).
    • At this starting point, the transmission rate is very slow (for example, just a fraction of the network’s true capacity).
  • Because TCP wants to discover how much bandwidth is actually available without wasting time, it grows cwndaggressively using incoming acknowledgments:
    • Send 1 segment, and when the acknowledgment returns, increase cwnd by 1 MSS so you can now send 2 segments.
    • When those 2 segments are acknowledged, increase cwnd by 2 MSS so you can now send 4 segments.
    • When those 4 are acknowledged, you send 8 segments, then 16, and so on.
    • The window doubles every single Round Trip Time (RTT), turning a “slow” start into explosive, exponential growth.
TCP slow start
TCP slow start

Since doubling traffic forever would eventually crash the network, Slow Start has two built-in safety brakes to pull it out of exponential growth:

  1. Brake 1: a timeout occurs
    • If a packet gets dropped and causes a timeout, TCP assumes it has hit a severe traffic jam.
    • It instantly resets cwnd back to 1 MSS and starts Slow Start all over again.
    • It calculates a new safety limit called ssthresh (short for slow-start threshold), setting it to half of whatever cwnd was right before the crash (cwnd / 2).
  2. Brake 2: Hitting ssthresh
    • Doubling the window past a certain point gets risky because you are getting close to the network’s breaking point.
    • TCP keeps track of that ssthresh safety threshold from previous sessions or cuts.
    • The moment cwnd reaches or crosses ssthresh, Slow Start ends.
    • TCP switches over to Congestion Avoidance mode, where it stops doubling and starts increasing cwnd much more cautiously and steadily.

Congestion Avoidance

  • When TCP switches to Congestion Avoidance, the value of cwnd is around half its value when congestion was last encountered.
  • And now rather than doubling the value of cwnd every RTT, TCP adopts a more conservative approach by increasing the value of cwnd by just 1 MSS every RTT.
    • E.g. if your window size allows you to send 10 segments in an RTT, each incoming ACK increases your window by 1/10 of an MSS, meaning the full window grows by just 1 MSS once all 10 ACKs arrive.
  • Even in congestion avoidance, packets can still get lost. How TCP reacts depends entirely on how it finds out about the loss:
    1. If a timeout happens: the network is heavily congested. TCP panics, drops cwnd all the way back down to 1 MSS, sets ssthresh to half of what cwnd was, and restarts Slow Start from scratch.
    2. If you get 3 duplicate ACKs: because the receiver is still sending duplicate ACKs, it means some data is still getting through. TCP realizes things aren’t totally broken, so isn’t so strict and cuts cwnd in half (plus adds a little buffer for the duplicate ACKs) and sets ssthresh to half of the previous window size.
TCP Congestion Avoidance
TCP Congestion Avoidance

TCP Congestion Control: Retrospective

  • TCP’s congestion control for figuring out how fast it can send data over the internet without overloading the network is sometimes called AIMD (Additive-Increase, Multiplicative-Decrease):
    • Additive Increase (+1): When everything is running smoothly, TCP slowly presses the gas pedal. It adds 1 extra packet (MSS) to its sending window (cwnd) for every round-trip time (RTT). It gently tests I the network can handle a little more.
    • Multiplicative Decrease (÷2): The moment it detects a dropped packet (via 3 duplicate ACKs), it panics slightly and slams the brakes, cutting its speed in half.
  • Because TCP constantly repeats this cycle – slowly climbing up, dropping by 50%, and slowly climbing back up – a graph of its speed over time looks like a row of saw teeth:
Additive-increase, multiplicative-decrease (AIMD) congestion control
Additive-increase, multiplicative-decrease (AIMD) congestion control
  1. Climb: 10→11→12→13→14 packets per second (Additive Increase)
  2. Drop: Packet dropped at 14! Cut in half to 7 (Multiplicative Decrease)
  3. Climb again: 7→8→9→10…
  • This continuous loop is called bandwidth probing. Since available internet bandwidth is constantly changing as other people log on and off, TCP continuously tests the limits without causing total network collapse.

Recent End-to-End TCP Congestion Control Algorithms

  • The “classic” TCP congestion control algorithms that we studied in the last section have largely been replaced by the newer flavors of TCP congestion control (in particular, BBR, and before that TCP CUBIC)

TCP Cubic

  • The problem with classic TCP is that when classic TCP drops a packet, it cuts its speed in half and slowly climbs back up at a rigid +1 packet per round trip.
  • This is overly cautious. If the network was handling high speed just a second ago, spending a long time crawling back up wastes available bandwidth.
  • So, instead of climbing back up in a straight diagonal line, TCP Cubic remembers its maximum speed before the crash (Wmax​) and uses a cubic function (an S-curve) to rebuild its speed in 3 smart phases:
    1. Fast recovery: right after the drop, it ramps up rapidly to get back close to where it was before the crash.
    2. Cautious probing: as it gets right near Wmax​, it flattens out and moves very slowly, carefully testing if the network is still congested.
    3. Rapid acceleration: If it passes Wmax​ without any packet loss, it assumes new bandwidth has opened up and accelerates rapidly again to find the new ceiling.
TCP Cubic
TCP Cubic
  • This matters because by spending more time near maximum capacity rather than slowly crawling back up, CUBIC gets significantly better throughput than classic TCP.

Evolution of the Web

  • Classic TCP (Reno): Dominated the early internet (1990s–2000s).
  • TCP CUBIC: Took over as the Linux default and powered ~50% of top websites by 2014.
  • BBR: A newer algorithm that surpassed CUBIC usage to become the dominant protocol

TCP Vegas

  • Classic TCP & CUBIC are loss-based, meaning they drive at full speed until they crash (drop a packet), then slam on the brakes i.e. they only react after congestion causes packet loss.
  • TCP Vegas, on the other hand, is delay-based, meaning it watches fo network delays to slow down before any packets are dropped.
  • Here’s how it works:
    1. Measures “Clear Road” Latency (RTTmin​): finds the fastest possible round-trip time (RTT) when the network is empty and packets experience zero queueing delay.
    2. Calculates Expected Speed: uses its current sending window (cwnd) and minimum delay to figure out its maximum potential speed (Speed=cwnd/RTTmin​).
    3. Compares Ideal Speed to Real Speed:
      • Actual Speed ≈ Expected Speed: The network is clear → Increase speed.
      • Actual Speed < Expected Speed: Packets are backing up in router queues, adding delay → Decrease speed before packets drop.

BBR: Bottleneck Bandwidth and Round-trip propagation time

  • BBR is Google’s modern TCP algorithm designed to maximise internet speed while eliminating unnecessary network lag.
  • Think of an internet connection as a water pipe:
    • Pipe Length: Round-Trip Time (RTT) – how long it takes data to travel back and forth.
    • Pipe Width: Bandwidth – how much data can flow through per second.
    • Pipe Capacity: Bandwidth-Delay Product (BDP) – the exact amount of data (ninflight​) needed to fill the pipe completely.
  • The goal of TCP should be to keep the pipe just full, but no fuller.
Traffic LevelSpeed (Throughput)Lag (Delay / RTT)What’s Happening?
Underfilled (ninflight​<BDP)LowLowestYou aren’t using the network’s full potential.
Just Right (ninflight​=BDP)MaximumLowestThe Goldilocks Zone: 100% link utilization with zero router queuing.
Overfilled (ninflight​>BDP)MaximumHighSpeed cannot increase further. Extra packets pile up in router buffers, creating artificial lag.
  • Older TCP algorithms kept shoving data until packets dropped, constantly forcing the network into the Overfilled state.
  • Instead of relying on packet loss or waiting for buffers to overflow, BBR actively measures the pipe’s volume and cycles through three repeating phases:
    1. Acceleration: ramps up speed to see if the network has gained new capacity.
    2. Cruising: scales back to match the exact speed at which the receiver is acknowledging data.
    3. Deceleration: intentionally slows down below the delivery rate to empty out any backed-up router queues and measure the true minimum delay.
BBW
BBW

BBR is preferred today because:

  • It eliminates “bufferbloat”: keeps downloads at peak speed without spiking latency (ping).
  • Smoother traffic: Uses pacing to spread out packets evenly rather than firing them in disruptive bursts.
  • Current standard: Developed by Google, BBR (now in version BBRv3) surpassed CUBIC and classic TCP to become the single most widely used congestion control protocol on the global internet.

Network Assisted Explicit Congestion Notification

  • The end-to-end approaches toward congestion control (discussed above) worked by the TCP sender looking for packet loss, RTT, and throughput.
  • Proposals have been made to allow the network to explicitly signal congestion to a TCP sender and receiver.
Network Assisted Explicit Congestion Notification
Network Assisted Explicit Congestion Notification
  • With an Explicit Congestion Notification (ECN) routers mark packets with a warning flag instead of throwing them away. This allows senders to gracefully slow down without losing data.
    1. Sender opts in (IP Header): the sender marks two bits in the packet’s IP header saying it supports the use of ECN.
    2. Router warns of rraffic (IP Header): a router along the path gets congested. Instead of dropping the packet, it flips these IP bits to say that there’s been congestion and forwards it on.
    3. Receiver echoes the warning (TCP Header): the destination receives the marked packet. To notify the sender, it sets the ECE (ECN-Echo) bit in its next TCP ACK packet.
    4. Sender slows down (TCP Header): the sender receives the ACK, cuts its sending rate in half, and sets the CWR (Congestion Window Reduced) bit in its next outgoing packet to confirm.
  • Key takeaways:
    • Because packets aren’t dropped to signal traffic, ECN avoids the delay of re-sending lost data.
    • Variants like DCTCP (Data Center TCP) rely heavily on ECN for high-speed, ultra-low-latency networks.
    • Over 80% of popular web servers and internet paths support ECN capabilities.

  1. It’s worth mentioning here that there are many different “flavours” of TCP congestion control used in the internet e.g. “Classic” TCP, TCP Vegas, CUBIC TCP, and BBR. We’ll look at each of these throughout this note. ↩︎