Congestion Control

How TCP avoids collapsing the network — slow start, congestion avoidance (AIMD), fast recovery, CUBIC and BBR, bufferbloat, and what it means for your applications.

Advanced 4 min readLesson 8 of 15 Interview Q&A

If every sender transmitted as fast as it could, router queues would overflow, packets would be dropped, senders would retransmit, and the network would spend its capacity carrying retransmissions. This happened in 1986 — congestion collapse — when Internet throughput fell by a factor of 1000. Van Jacobson's congestion control algorithms fixed it and are a big reason the Internet works at all.

The congestion window

Besides the receiver's window (flow control), the sender keeps a congestion window (cwnd): its own estimate of how much the network can absorb.

bytes in flight≤min⁡(cwnd, rwnd)throughput≈cwndRTT\text{bytes in flight} \le \min(\text{cwnd},\ \text{rwnd}) \qquad \text{throughput} \approx \frac{\text{cwnd}}{\text{RTT}}

There's no explicit signal from the network about capacity, so TCP probes: it increases cwnd until it sees signs of congestion (packet loss, or rising delay), then backs off.

Classic TCP (Reno)

  1. Slow start — begin with cwnd ≈ 10 segments (~14 KB) and double it every RTT (+1 segment per ACK). Despite the name, it grows exponentially.
  2. When cwnd reaches the slow-start threshold (ssthresh), switch to congestion avoidance: add about 1 segment per RTT (linear).
  3. On 3 duplicate ACKs (one packet lost, the rest arriving): halve cwnd and set ssthresh to it — fast recovery — then continue linearly.
  4. On a timeout (severe loss): set ssthresh = cwnd / 2, reset cwnd to 1 segment, and slow-start again.
123456789101112cwnd12481617181920101112
Per RTT: slow start doubles to ssthresh = 16, then +1 per RTT; a loss at RTT 9 halves cwnd. The sawtooth of AIMD.

This is AIMD — additive increase, multiplicative decrease. AIMD is provably fair: competing flows on a shared link converge to equal shares.

Why slow start matters to web performance

A new connection starts at ~14 KB per RTT and needs several round trips to reach full speed. A 500 KB page over a fresh connection with 100 ms RTT needs about 5–6 round trips just from slow start, regardless of your bandwidth.

  • Reuse connections (keep-alive, HTTP/2, connection pools) to keep a warm cwnd.
  • Keep the critical first response small (critical CSS inline, around the first 14 KB).
  • Put servers close to users (CDNs) to cut RTT, since every round trip counts.

Modern algorithms

AlgorithmSignalIdeaUsed by
Reno / NewRenoLossAIMDHistorical baseline
CUBICLossWindow grows as a cubic function of the time since the last loss: fast recovery to the previous level, careful probing near it, aggressive beyondDefault in Linux, Windows, macOS
BBR (v1–v3)Bandwidth + RTT modelMeasure the bottleneck bandwidth and minimum RTT; pace sending at that rate rather than filling buffersGoogle, YouTube, many CDNs
Vegas, CopaDelayBack off when RTT rises, before lossResearch, some products
DCTCPECN marksFine-grained reaction to congestion marksData centres

Bufferbloat

Routers and modems with huge buffers let loss-based TCP fill them, adding hundreds of milliseconds (sometimes seconds) of queuing delay. That's why a video call stutters when someone else in the house starts a large upload.

Fixes:

  • Active queue management (AQM) in routers: CoDel, fq_codel, CAKE drop or mark packets early when queuing delay grows, and isolate flows from each other.
  • ECN (explicit congestion notification): routers mark packets instead of dropping them, and the sender slows down without losing data. L4S extends this for very low latency.
  • Delay-aware algorithms like BBR.

Fairness and the real world

  • AIMD flows share a bottleneck roughly equally per flow, so an application opening 6 parallel connections gets 6 shares. Browsers historically did exactly that with HTTP/1.1.
  • Flows with shorter RTTs grow faster and get more bandwidth (RTT unfairness).
  • UDP applications have no built-in congestion control; well-behaved ones (QUIC, WebRTC) implement it themselves, and network operators worry about those that don't.

Checking your connections

Shell
sysctl net.ipv4.tcp_congestion_control        # e.g. cubic
sysctl -w net.ipv4.tcp_congestion_control=bbr # switch (needs the module)
ss -ti                                         # per-connection cwnd, rtt, retransmits
Key takeaways
  • Congestion control protects the network; cwnd limits data in flight; throughput ≈ cwnd / RTT.
  • Slow start doubles cwnd each RTT; congestion avoidance adds 1 segment per RTT.
  • On loss, cut cwnd (halve on dup ACKs, reset on timeout): AIMD is stable and fair.
  • CUBIC is the common default; BBR models bandwidth and RTT to avoid filling queues.
  • Bufferbloat adds latency; AQM (fq_codel) and ECN fix it.
  • Reuse connections and reduce RTT — slow start penalises fresh connections.
Interview questions
QWhy is it called slow start if the window grows exponentially?easy

Compared with what came before — sending a full receiver window immediately — starting from a small window is slow. It then doubles each RTT until it hits ssthresh or sees loss.

QWhy might adding more bandwidth not make a website load faster?medium

Page loads are often dominated by round trips: DNS, the TCP and TLS handshakes, slow start's ramp-up, and dependent requests. These depend on latency (RTT), not bandwidth. Reducing round trips (connection reuse, HTTP/2–3, CDNs, preconnect) helps more.