awesome-everything RU
↑ Back to the climb

Networking & Protocols

Flow control and congestion control

Crux Sliding windows let the receiver pace the sender; slow start and CUBIC let TCP discover the network''''s capacity without overloading it.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at middle altitude — in the sky
◷ 16 min

A fresh TCP connection between London and Sydney has no idea how fast the link is. It starts cautiously, doubling its send rate every round-trip until it hits a limit — then it backs off and tries again. This dance between sender and network is how TCP fills a 10 Gbps pipe or politely shares a 1 Mbps one.

Sliding window and flow control

Once established, every TCP segment carries a window size — the number of bytes the receiver is willing to accept beyond the last acknowledged byte. The sender keeps a sliding window of unacknowledged bytes in flight, bounded by the minimum of the receiver’s advertised window and its own congestion window. As ACKs arrive the window slides forward, allowing new bytes. If the receiver’s application is slow to drain the socket buffer, the window shrinks; if the buffer fills entirely the receiver advertises window=0 and the sender pauses. This is end-to-end flow control: the receiver dictates the pace, the sender obeys.

MSS, window scaling, and SACK

Three options negotiated during the SYN/SYN-ACK exchange significantly affect throughput:

Maximum Segment Size (MSS): the largest TCP payload the stack can handle without IP fragmentation. Typical: 1460 bytes on Ethernet (1500 MTU minus 20 IP + 20 TCP headers), or 1220 bytes on tunnelled networks.

Window Scaling (RFC 7323): the 16-bit window field is multiplied by 2^scale, allowing windows up to 1 GiB. Without this, a 64 KiB window cap on a 100 ms RTT link limits throughput to ~5 Mbps regardless of actual link speed (bandwidth-delay product = 64 KiB / 0.1s ≈ 640 KiB/s). Essential for high-bandwidth long-RTT paths.

Selective Acknowledgements (SACK, RFC 2018): the receiver lists exact ranges of bytes received past a gap, so the sender retransmits only the missing pieces rather than everything after the gap. On a lossy long-RTT path SACK can double effective throughput.

Window and throughput numbers
Ethernet MSS
1460 bytes (1500 MTU)
16-bit window max
64 KiB (capped without scaling)
Window scale max
1 GiB (2^30)
Linux default IW
10 MSS (~14.6 KB)
Bandwidth × RTT (BDP)
100 Mbps × 100 ms = 1.25 MB
BDP sets min window needed
to fill a high-BDP path

Retransmit timer math (RFC 6298)

If a segment goes un-ACKed within the retransmission timeout (RTO), the sender resends it. RFC 6298 specifies:

SRTT ← (1 − 1/8)·SRTT + (1/8)·new_RTT
RTTVAR ← (1 − 1/4)·RTTVAR + (1/4)·|SRTT − new_RTT|
RTO = SRTT + max(G, 4·RTTVAR)

Where SRTT is the smoothed RTT and RTTVAR is RTT variance (EWMAs). The first RTO defaults to 1s; after a timeout it doubles (exponential backoff) until either the segment arrives or the connection gives up. Karn’s algorithm forbids sampling RTT from retransmitted segments because the responding ACK is ambiguous.

Modern Linux uses RACK-TLP (RFC 8985) for faster loss detection: RACK declares a segment lost when a later segment was ACKed and a reorder-window has expired — no need to wait for the RTO timer. TLP (Tail Loss Probe) re-sends the last unacknowledged segment one RTT after the last send to avoid hanging on the final packet of a flight.

Quiz

What does the receiver's advertised window in the TCP header mean?

Slow start and congestion avoidance

A fresh connection has no idea how fast the network is. Slow start opens the congestion window exponentially (1, 2, 4, 8, … MSS per RTT) until either a loss occurs or the slow-start threshold (ssthresh) is reached. After that, congestion avoidance grows the window linearly (~1 MSS per RTT for Reno/CUBIC).

On loss, the algorithm differs by variant:

  • Reno: halves the window, then linear increase.
  • CUBIC (Linux default since 2.6.19): reduces less aggressively then probes back with a cubic curve — faster recovery on high-BDP paths.
  • BBR: ignores loss entirely as a congestion signal; uses RTT + delivered-bytes measurements instead (covered in the BBR lesson).
Order the steps

Order the sender's congestion-window growth in TCP slow start:

  1. 1 Initial: cwnd = 10 MSS (Linux default IW=10)
  2. 2 After 1 RTT and ACKs: cwnd doubles to 20 MSS
  3. 3 After 2 RTT: cwnd doubles to 40 MSS
  4. 4 Continues exponential growth until ssthresh or loss
  5. 5 On reaching ssthresh: enter congestion avoidance (linear +1 MSS/RTT)
  6. 6 On packet loss: reduce cwnd per the congestion-control variant
Quiz

Why is exponential backoff used for retransmissions instead of a constant timer?

Trace it
1/3

Trace a SACK recovery episode after one packet is lost in a window of 10 segments.

1
Step 1 of 3
Segments 1-10 are sent. Segment 5 is dropped. Segments 6-10 arrive. What does the receiver report?
2
Locked
Without SACK, what would the sender have to retransmit?
3
Locked
Why does this matter on a 200 ms RTT path?
Why this works

Why slow start starts fast. The name is misleading: Linux 3.0+ (RFC 6928) sets the initial congestion window (IW) to 10 MSS (~14.6 KB), not 1 MSS. This means the first burst of data is already 10 segments, chosen to match the typical HTTP response size for small API calls. Slow start only looks slow compared to the eventual bandwidth; against the classic IW=1 it is a 10x improvement for the first RTT.

Recall before you leave
  1. 01
    Explain how Window Scaling (RFC 7323) affects achievable throughput on a 100 ms RTT, 1 Gbps link.
  2. 02
    What is RACK-TLP and why does it improve on the classic RTO-based loss detection?
  3. 03
    Why does a connection with high random loss perform poorly under CUBIC but not under BBR?
Recap

TCP flow control uses a sliding window: the receiver advertises how many bytes it can accept, the sender never exceeds that. Three options negotiated in SYN/SYN-ACK sharply affect throughput: MSS (segment size), Window Scaling (extends 64 KiB to 1 GiB window), and SACK (pinpoints missing ranges so only lost segments are retransmitted). Congestion control starts fresh connections in slow start (exponential window growth) then switches to congestion avoidance (linear growth) after hitting ssthresh. CUBIC, Linux’s default since 2006, uses a cubic recovery curve after loss. The retransmission timer is computed from smoothed RTT (RFC 6298) with exponential backoff. RACK-TLP, the default since Linux 5.x, detects loss faster by watching ACK ordering rather than waiting for a timer to fire.

Connected lessons
appears again in162
Continue the climb ↑TCP options and common pathologies
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources5
expand
  1. 01
  2. 02
  3. 03
  4. 04
  5. 05

Trademarks belong to their respective owners. Editorial reference only.