completefrontend
Open lab My progress
THE WEB PERFORMANCE FIELD GUIDE

Congestion control

Why the same page loads at different speeds on the same line: how CUBIC and BBR decide how much to send, what bufferbloat does, and what the first flight holds.

By the end, you can
  • 01
    Explain how much a sender sendsUse the congestion window, the line's capacity and the router's buffer to say when data flows, waits or gets dropped.
  • 02
    Tell CUBIC and BBR apartSay what each one watches, how each grows, and what each did on a small and a big buffer.
  • 03
    Spot bufferbloatExplain why one download can make every round trip on a line ten times longer, and what fixes it.
  • 04
    Count the first flightWork out how many round trips a response needs on a new connection, and what a frontend team can change.

The same page, the same line, three speeds

It's evening. Asha opens Ravi's Mint tea page on her phone, on her home Wi-Fi. Most days, it shows up almost at once. Tonight, the screen stays white for about a second, and the photo takes more than two. In the next room, her brother is downloading a big game update.

Asha's line is fast enough for both of them. So why does his download slow her page down so much? And why is it bad on some evenings, and fine on others?

The course built a line like Asha's and opened the page three times. Once, the line was quiet. Twice, a big download ran at the same time. Both downloads were the same file. Only the server sending it was different. Here is when the page finished loading:

One page, one line, three loadsPop out in the code editor (opens in a new tab)JavaScript
// Asha opens the Mint tea page on the same line, three ways.// When the page finished loading, in ms: the middle of three visits each.const loaded = { quiet: 196.8, cubicDownload: 2288.1, bbrDownload: 415.4 }; console.log(`Quiet line: ${loaded.quiet} ms`);console.log(`Brother's download from a CUBIC server: ${loaded.cubicDownload} ms`);console.log(`Brother's download from a BBR server: ${loaded.bbrDownload} ms`);
  • Lines 1 and 2 are comments. Each time is in milliseconds (ms), thousandths of a second. Each is the middle of three visits.
  • Line 3 holds the three recorded times.
  • Lines 5 to 7 print Quiet line: 196.8 ms, Brother's download from a CUBIC server: 2288.1 ms and Brother's download from a BBR server: 415.4 ms.

Same page, same phone, same line. With one download, the page took 2.3 seconds. With the other, 0.4 seconds. Here is Asha's screen half a second after she opened the page:

Asha's screen 0.5 seconds after she opened the Mint tea page, three times on the same line. Quiet line: the whole page is there, and it finished loading at 0.2 seconds. Download from BBR: the whole page is there, and it finished loading at 0.4 seconds. Download from CUBIC: nothing is drawn yet, and it finished loading at 2.3 seconds.Asha's screen, 0.5 s after she opened the pageQuiet lineQuietThe whole Mint tea page: the title, the photo, the price and the button.loaded at 0.2 sDownload from BBRBBRThe whole Mint tea page, the same as on the quiet line.loaded at 0.4 sDownload from CUBICCUBICnothing drawn yetloaded at 2.3 s
The same page on the same line, 0.5 seconds in. Only the download's server changed, and the page that waited was the one behind the CUBIC download.

What changed was the download server's congestion control: the part of a sender that decides how much to send, and how fast. CUBIC and BBR are two kinds. A server has to guess, because it can't see the line. It only hears back from the other end. This lesson shows how each one guesses, and why one guess filled Asha's line with waiting packets.

Real-life analogyOne till at the corner shop

The corner shop has one till. The man ahead of Asha tips his whole trolley onto the belt. Asha has one carton of milk. She waits for all of it, though the cashier works as fast as ever. If he put his things down a few at a time, as they were scanned, she could slip her milk in between.

In real life: The one till
In JavaScript: The slowest link on the line, into Asha's home
In real life: The belt where shopping waits
In JavaScript: The router's buffer: packets waiting their turn
In real life: Tipping a whole trolley onto the belt
In JavaScript: A sender that sends until packets are lost: CUBIC on a big buffer
In real life: Putting items down as the cashier scans them
In JavaScript: A sender that matches the line's pace: BBR
In real life: Asha's one carton of milk
In JavaScript: Her page's few packets
The main idea

A sender can't see the line, so it guesses how much to keep on its way. CUBIC guesses by sending more until a packet is lost. BBR guesses by measuring the line. On a line with a big buffer, a bad guess doesn't make anything faster. It makes every round trip on the line longer, for everyone sharing it.

How the course recorded it:

  • The line was emulated by a relay program on one computer: 10 Mbit/s from the server to Asha, and 20 ms each way. So a round trip took 40 ms.
  • The router's buffer held 512 packets (the big buffer) or 32 (the small one). A packet that reached a full buffer was dropped.
  • The senders were real: quiche 0.30.1, Cloudflare's QUIC library, with its CUBIC sender or its BBR sender, bbr2_gcongestion.
  • quiche's example server paces its packets only on Linux. So the course changed it to hold each packet until the send time quiche gave it.
  • The download was 12,000,000 bytes. Asha's visits were in Chrome 157.0.8103.52, over HTTP/3, on the big buffer, 4 seconds after the download started.
  • Every case was recorded three times, taking turns. For each download, the page shows the one with the middle round trip. For Asha's visits, it shows the middle of the three.

How much a sender keeps in flight

TCP connections and slow start met the congestion window. It's how much a sender may send before it stops and waits for acknowledgments, the short notes that say "got it". Data that has left but isn't acknowledged yet is in flight.

So how much should be in flight? Start with the line. Asha's line carries 10 megabits each second. A round trip takes 40 ms. How much is on its way at any moment?

What one round trip holdsPop out in the code editor (opens in a new tab)JavaScript
// Asha's line: how many bytes are on their way during one round trip.const megabitsPerSecond = 10;const roundTripMs = 40; const bytesPerMs = (megabitsPerSecond * 1_000_000) / 8 / 1000;const lineFull = bytesPerMs * roundTripMs;console.log(`${bytesPerMs} bytes leave every ms`);console.log(`One round trip holds ${lineFull} bytes`);
  • Line 2 is the line's speed. Line 3 is a round trip with nothing else on the line.
  • Line 5 turns megabits each second into bytes each ms. A byte is 8 bits.
  • Line 6 multiplies that by the round trip.
  • Lines 7 and 8 print 1250 bytes leave every ms and One round trip holds 50000 bytes.

That number has a name: the bandwidth-delay product, or BDP. It's the line's speed times its round trip. With 50,000 bytes in flight, the line is busy all the time, and nothing waits. Why it matters: with less, the line sits idle part of the time. With more, nothing goes any faster.

So where does the extra go? It waits. Somewhere on the way, one link is the slowest. It's called the bottleneck. Here it's the link into Asha's home. The router in front of it has a buffer: a queue where packets wait their turn.

Asha's line, from the server to her phone. About 50,000 bytes can be on their way during one round trip. Anything more waits in the router's buffer, which holds 512 packets on the big setting. The router sends packets on at 10 Mbit/s. A packet that arrives when the buffer is full is dropped.serveron the wire50,000 bytesin one round trip, 40 msrouter's bufferpackets wait here10 Mbit/sAshabuffer full: a new packet is dropped
About 50,000 bytes fit on the line during one round trip. More than that waits in the router's buffer. When the buffer is full, a new packet is dropped.

A buffer is useful. Packets often come in bursts, and the buffer smooths them out. But every packet in it makes the ones behind it wait. How long? Say the big buffer is full:

The wait behind a full bufferPop out in the code editor (opens in a new tab)JavaScript
// A new packet joins the back of the buffer on Asha's line.const waiting = 512; // packets already in the bufferconst packetBytes = 1378; // a 1,350-byte packet, plus 28 bytes of IP and UDP headersconst bytesPerMs = 1250; // 10 Mbit/s const waitMs = (waiting * packetBytes) / bytesPerMs;console.log(`It waits ${waitMs.toFixed(1)} ms before it leaves`);
  • Line 2 is the packets already waiting.
  • Line 3 is one packet's size on the line: QUIC's 1,350 bytes, plus 28 bytes of headers.
  • Line 4 is the line's speed: 1,250 bytes every ms.
  • Line 6 works out how long the router takes to send everything ahead of the new packet.
  • Line 7 prints It waits 564.4 ms before it leaves.

That's over half a second, added to a round trip. And when the buffer is full, a new packet doesn't wait at all. The router drops it. Why it matters: the sender's window decides which of these happens. Keep about a BDP in flight, and the buffer stays nearly empty. Send far more, and it fills.

CUBIC: grow until a packet is lost

Start with CUBIC. RFC 9438, the standard that defines it, says it's the default in the Linux, Windows and Apple network stacks. In Linux's own build settings, CUBIC is the default choice. In quiche, it's the default too.

CUBIC has no picture of the line. Its main signal is a lost packet. While nothing is lost, it keeps sending more. When a packet goes missing, it reads that as "the line is full", and backs off. It works like a party next door:

Real-life analogyTurning the music up until the neighbour knocks

You turn the music up and up, until the neighbour knocks on the wall. You turn it down a lot. Then you turn it back up, quickly at first, and slowly as you get near where the knock came. You stay there a while. Later, you try a little louder, then louder still, until the next knock.

In real life: The volume
In JavaScript: The congestion window
In real life: The neighbour knocking
In JavaScript: A lost packet
In real life: Turning down to 70%
In JavaScript: CUBIC's cut after a loss
In real life: Going back up to where the knock came, then waiting there
In JavaScript: Growing back to W_max, and staying near it
In real life: Trying a little louder later
In JavaScript: Growing past W_max, faster and faster

After a loss, CUBIC remembers the window it had. RFC 9438 calls it W_max. It cuts the window to 70% of that, and grows it again along a curve. The curve gives CUBIC its name: it's a cubic, a curve with a power of three. Here it is, with the RFC's numbers:

CUBIC's window after a lossPop out in the code editor (opens in a new tab)JavaScript
// CUBIC after a loss, with RFC 9438's numbers. Windows count packets.const C = 0.4;const beta = 0.7;const wMax = 100; // the window when the loss happenedconst K = Math.cbrt((wMax - wMax * beta) / C); // seconds to grow back to wMax for (const t of [0, 2, K, 6, 8]) {  const cwnd = C * (t - K) ** 3 + wMax;  console.log(`${t.toFixed(1)} s: ${Math.round(cwnd)} packets`);}
  • Line 2 is C, the RFC's number for how steep the curve is. Line 3 is beta, the cut to 70%.
  • Line 4 is wMax, the window when the packet was lost: 100 packets here.
  • Line 5 works out K: how many seconds the curve takes to climb back to wMax.
  • Line 7 picks five moments, with K among them.
  • Line 8 is CUBIC's curve. Line 9 prints each moment's window.
  • It prints 0.0 s: 70 packets, 2.0 s: 96 packets and 4.2 s: 100 packets. Then 6.0 s: 102 packets and 8.0 s: 122 packets.

Read the numbers in order. The window jumps back up fast at first. Near 100 packets, where the last loss came, it almost stops. Then it grows again, faster and faster. CUBIC spends a long time near the size that worked last time. Only then does it look for more.

Before the first loss, a new connection is in slow start, the doubling from lesson 2.3. RFC 9438 asks CUBIC to use HyStart++, which can end slow start early, when round trips start to grow. After that, only a loss stops the growth.

On the course's line, CUBIC did just this. On the small buffer, its window rose and fell like a saw. It moved the download at 9.1 Mbit/s and lost 217 packets. Round trips stayed short: 61 ms in the middle. On the big buffer, nothing was lost for a long time. So the window kept growing, up to 765,265 bytes. That's 15 times what the line holds. Why it matters: every byte past the line's 50,000 had to wait in the buffer.

BBR: measure the line, then match it

BBR asks a different question. Not "was a packet lost?", but "how fast does the line deliver, and how short can a round trip be?" Its name says so: Bottleneck Bandwidth and Round-trip propagation time. Google's team described it in an article in Communications of the ACM. The IETF's draft describes its third version.

BBR reads the acknowledgments. Each one says how much data arrived, and how long a packet took to come back. From these, BBR keeps two numbers: the fastest delivery it has seen lately, and the shortest round trip. Here is its model of Asha's line:

BBR's model of the linePop out in the code editor (opens in a new tab)JavaScript
// BBR's model of Asha's line, from what the acknowledgments told it.const bandwidth = 1250; // bytes per ms: the fastest delivery it measuredconst minRoundTripMs = 40; // the shortest round trip it measured const bdp = bandwidth * minRoundTripMs; // what one round trip holdsconst gapMs = 1350 / bandwidth; // time between two 1,350-byte packetsconst cwnd = 2 * bdp; // the most it lets be in flightconsole.log(`Line full: ${bdp} bytes`);console.log(`One packet every ${gapMs} ms`);console.log(`Window: ${cwnd} bytes`);
  • Line 2 is the fastest delivery it measured: 1,250 bytes every ms, the line's speed.
  • Line 3 is the shortest round trip it measured: 40 ms, when nothing was waiting.
  • Line 5 multiplies them. That's what the line holds: the BDP again.
  • Line 6 spaces the packets out at the line's speed. Sending at a steady pace like this is called pacing.
  • Line 7 lets at most twice the BDP be in flight.
  • Lines 8 to 10 print Line full: 50000 bytes, One packet every 1.08 ms and Window: 100000 bytes.

Pacing is BBR's main control. The window is only a limit. Think of pouring tea:

Real-life analogyPouring tea through a strainer

Tip the whole pot in at once, and tea pools in the strainer, and may spill. A careful pourer watches how fast it drains, and pours at that pace. Only a little sits in the strainer. Now and then, they pour a bit faster to see if it drains faster. Now and then, they stop and look at the empty strainer.

In real life: How fast tea drains through the strainer
In JavaScript: The bottleneck's speed, the delivery rate BBR measures
In real life: Pouring at that same pace
In JavaScript: Pacing at the measured rate
In real life: Tea sitting in the strainer
In JavaScript: Packets waiting in the buffer
In real life: Pouring a little faster for a moment
In JavaScript: Checking whether the line got faster
In real life: Stopping a moment to see it empty
In JavaScript: Measuring the shortest round trip again

BBR moves through four states:

  • Startup doubles the sending rate each round trip, until the delivery rate stops growing.
  • Drain sends slower for a moment, to empty the queue Startup made.
  • ProbeBW is where it spends most of its time. It sends at the measured rate, with short spells a little faster, then a little slower.
  • ProbeRTT now and then cuts what's in flight to half a line-full, for at least 200 ms. That lets it measure the empty-line round trip again. The draft keeps the shortest round trip for 10 seconds.

On the course's line, BBR's window stayed small. On the big buffer, it reached 125,387 bytes, about a sixth of CUBIC's. That's about two and a half times the line's 50,000 bytes: the draft also leaves room for acknowledgments that arrive in bunches. It moved the download at the same 9.2 Mbit/s, and lost 0 packets. Round trips took 86.2 ms in the middle. That's a small queue, about one line-full, which the bigger window allows. Here are both windows over the same download:

The congestion window during the same 10.4-second download on the big buffer, drawn every half second to the same scale. CUBIC's window reached 765,265 bytes, and a round trip took 490.8 ms. BBR's window reached 125,387 bytes, and a round trip took 86.2 ms. Both moved the download at 9.2 Mbit/s.CUBICwindow up to 765,265 bytes, round trip 490.8 msBBRwindow up to 125,387 bytes, round trip 86.2 mseach bar: half a second
The same download, the same speed. CUBIC's window kept growing into the big buffer. BBR's stayed between two and three round trips of data.

Now pick a sender and a buffer, and compare the recorded curves:

Playground: one download, two senders, two buffers
CUBIC, big buffer9.2 Mbit/s
Window and data in flight, KB8000A small probe's round trip, ms60000 s10.4 s

window in flight round trip

Download speed
9.2 Mbit/s
Largest window
765 KB
Round trip, the middle
490.8 ms
Packets the router dropped
208
Try it yourself
CUBIC, big buffer: round trips of 490.8 ms

Nothing is lost for a long time, so CUBIC keeps growing. The extra data waits in the big buffer, and every round trip on the line gets longer.

Real downloads of 12,000,000 bytes from quiche's example server, on the course's emulated line: 10 Mbit/s, 40 ms round trip. Each case was recorded three times, taking turns; this is the download with the middle round trip.

In the playground, the solid line is the window and the dashed line is the data in flight. The bottom chart is the round trip a small probe saw. Read this table across: each row asks one question of both senders.

CUBIC and BBR side by side
QuestionCUBICBBR
What tells it the line is full?A lost packet.Its model: the fastest delivery and the shortest round trip it measured.
How does it grow?Along a cubic curve: fast, then flat near the last loss, then faster.It doubles in Startup, then sends at the measured rate, a little above and below in turns.
How much does it keep in flight?Whatever the window has grown to, until a loss.A few round trips of data at most.
On the small buffer9.1 Mbit/s, 217 packets dropped, round trips of 61 ms.9.1 Mbit/s, 61 packets dropped, round trips of 63.7 ms.
On the big buffer9.2 Mbit/s, 208 packets dropped, round trips of 490.8 ms.9.2 Mbit/s, 0 packets dropped, round trips of 86.2 ms.

Bufferbloat: a waiting room that's too big

Now Asha's evening makes sense. Her page's packets share the line with the download. They join the same buffer, at the back. This has a name. bufferbloat.net calls it bufferbloat: "the undesirable latency that comes from a router or other network equipment buffering too much data." Latency is waiting time.

Real-life analogyA waiting room with too many chairs

A clinic adds more chairs to its waiting room. The doctor sees patients no faster. Now the room just holds more people, and everyone waits longer. Someone with a quick question waits behind them all.

In real life: The doctor
In JavaScript: The line, sending packets at its speed
In real life: The chairs
In JavaScript: The router's buffer
In real life: Adding more chairs
In JavaScript: A bigger buffer
In real life: A patient with a quick question
In JavaScript: One packet of Asha's page
In real life: A nurse who sends people away when the wait gets long
In JavaScript: Active queue management, like CoDel

The course measured it with a small probe: a tiny packet sent across the line every 50 ms, and timed there and back. It sees what any other request on the line sees. On the quiet line, a round trip took 41.8 ms. During the download, the middle round trip was:

  • CUBIC, small buffer: 61 ms.
  • BBR, small buffer: 63.7 ms.
  • CUBIC, big buffer: 490.8 ms.
  • BBR, big buffer: 86.2 ms.

With CUBIC on the big buffer, every round trip took about half a second. That's about 12 times the quiet line. The line's speed never changed. Packets just waited longer. Why it matters: a page load is a chain of round trips. When each one costs half a second, a few of them cost seconds.

Asha's visits show that chain. Pick one, and see when each step happened:

Playground: Asha's visit, four ways
Quiet line0 to 2.5 s
  • Connection ready43.1 ms
  • First paint128 ms
  • HTML arrived188.2 ms
  • Page loaded196.8 ms
The page's packets waited in the buffer, the middle
5.7 ms
Try it yourself
Page loaded at 196.8 ms

Nothing else is on the line. Each round trip takes about 40 ms, and the whole page is there in a fifth of a second.

Real visits in Chrome over HTTP/3, through the course's emulated line with the big buffer. Each case was recorded three times, taking turns, each in a fresh browser; every number is the middle of the three.

On the quiet line, the connection was ready at 43.1 ms: one round trip. Behind the CUBIC download, it took 399.3 ms. The HTML arrived at 1861.4 ms, and the photo after it. Those visits also varied a lot, from 1.3 to 3.3 seconds. The buffer was fuller at some moments than others. A full buffer also drops Asha's own packets, and each lost packet costs another long round trip.

Who can fix it? Two places:

  • The router. Active queue management drops packets early, before the queue gets long. CoDel watches how long packets wait. It starts dropping when the wait stays above 5 ms for 100 ms. FQ-CoDel also gives each flow its own small queue. Its RFC says this protects "low-rate traffic such as DNS, web, and videoconferencing traffic".
  • The sender. BBR doesn't need a full buffer to find the line's limit. The BBR article reports that on YouTube, BBR cut the median round trip by 53% on average worldwide. In the developing world, it was more than 80%.

Neither is in a frontend team's hands. The next two sections are.

The first flight: ten packets

The download ran for seconds. Asha's page is the opposite: a new connection, and some tens of kilobytes. For that, one number matters most. The initial window is how much a sender may send before the very first acknowledgment comes back. All of that is the first flight.

  • For TCP, RFC 6928 allows 10 segments, at most 14,600 bytes. In Linux, TCP_INIT_CWND is 10.
  • For QUIC, RFC 9002 says ten times the largest packet, but no more than 14,720 bytes.
  • quiche starts with 10 packets, and its example server sends packets of up to 1,350 bytes. So its first flight is 13,500 bytes.
Real-life analogyA lift that holds ten

A hotel lift holds ten people. A group of ten goes up in one trip. A group of twelve needs two trips, and the last two wait the whole time for the lift to come back. Sending ten is quick. Sending eleven costs a whole extra trip.

In real life: One trip up and down
In JavaScript: One round trip
In real life: Ten people on the first trip
In JavaScript: The initial window: 10 packets
In real life: A group of twelve
In JavaScript: A response a little too big for the first flight
In real life: A bigger lift for each next trip
In JavaScript: Slow start: each round carries about twice as much

The course asked the server for the Mint tea page at ten sizes. Each was a new connection, on the quiet line. The server's log, a qlog file, lists every packet it sent and every acknowledgment it got. Whenever the response was big enough, the first flight held exactly 13,500 bytes: the initial window. Usually, that was 13 packets. Three small ones finished setting up the connection and HTTP/3. The other ten carried 12,460 bytes of the response. The next round carried 27,000 bytes, twice as much: slow start. That gives a simple model of the recorded rounds:

How many round trips a response needsPop out in the code editor (opens in a new tab)JavaScript
// A model of the recorded rounds: the first flight carried 12,460 bytes// of the response, and each round after it carried about twice as much.function roundTrips(responseBytes) {  let carried = 12460;  let sent = carried;  let rounds = 1;  while (sent < responseBytes) {    carried *= 2;    sent += carried;    rounds += 1;  }  return rounds;} for (const size of [12000, 14000, 60000]) {  const n = roundTrips(size);  console.log(`${size} bytes: ${n} round trip${n === 1 ? "" : "s"}`);}
  • Lines 1 and 2 say what the model is.
  • Line 4 starts with the first flight's share of the response.
  • Lines 7 to 11 add rounds, each carrying twice the one before, until the whole response has left.
  • Line 15 tries three sizes. Line 17 prints each one's round trips.
  • It prints 12000 bytes: 1 round trip, 14000 bytes: 2 round trips and 60000 bytes: 3 round trips.

The model matches every size the course fetched. Here are three of them, as the server sent them:

Each response's rounds on a new connection, on the quiet line, from a CUBIC server. 12,000 bytes: 1 round trip, sending 14 packets. 14,000 bytes: 2 round trips, sending 13 packets, then 3 packets. 60,000 bytes: 3 round trips, sending 13 packets, then 21 packets, then 19 packets.12 KB page14 packets1 round trip14 KB page13 packets3 packets2 round trips60 KB page13 packets21 packets19 packets3 round trips
Each bar is one round trip of sending, as wide as its bytes. The first is never wider than the first flight.

Look at the 14 KB page. The 14 KB rule from lesson 2.3 says it fits in one round trip. Here it didn't. The rule comes from TCP's 1,460-byte segments. This server's packets were smaller. Of the 13,500 bytes, the three setup packets and each packet's own header took the other 1,040. So the page's last 1,601 bytes waited for a second round trip. Why it matters: the first flight depends on the server. Leave some room under it.

Slide through the sizes, and watch the rounds:

Playground: how many round trips a response needs
Round trips of sendingresponse in 172.6 ms
  1. Round 113 packets, 13,500 bytes, 12,460 of the response
  2. Round 23 packets, 1,758 bytes, 1,601 of the response
Try it yourself
14,000 bytes: 2 round trips

The first flight carries 12,460 bytes of it. The rest has to wait for acknowledgments, 1 more round trip.

Real fetches of the Mint tea page at each size, each on a new connection, from quiche's example server with CUBIC, on the quiet line. Each size was fetched three times, and needed the same number of round trips every time.

BBR started from the same 13,500 bytes. But quiche's BBR also grew its window from the handshake's own acknowledgments, so its first flight held 15,508 bytes.

And the browser doesn't choose any of this. For a page, the server sends the bytes, so the server's sender decides. Chrome mostly sends acknowledgments. For what Chrome sends itself, its QUIC code picks CUBIC by default.

What a frontend team can change

You can't change Asha's router, or her brother's download. But you control your page. And you can ask your server or CDN team for changes. Here's what the recordings say:

  • Make the first response small. Behind the CUBIC download, Ravi trimmed the page from 60 KB to 12 KB. Its HTML arrived at 971.4 ms instead of 1861.4 ms. The page loaded at 1481.5 ms instead of 2288.1 ms. On this busy line, each round trip saved was worth about half a second. Compression helps the same way.
  • Reuse connections. An open connection has already grown its window. A new one starts again with the first flight. Fewer origins means fewer new connections.
  • Don't compete with your own page. A big download that starts while the page loads, like an autoplaying video, fills the buffer just like the brother's download did. Start it after the page is ready.
  • Ask about the sender. On Linux, it's a server setting, tcp_congestion_control. BBR is an option in Linux's build settings, and CUBIC is the default. For QUIC, it's the library's setting, like quiche's list of algorithms. A CDN chooses for its own servers.
  • Ask about idle connections. Linux shrinks the window of a connection that sat idle. The setting, tcp_slow_start_after_idle, is on by default.

Each change below belongs to someone. Sort it by who can make it:

Who can change it?
  • Cut the HTML's first response from 60 KB to 12 KB
  • Serve the photos from the page's own origin, not a second one
  • Start the big background video only after the page has loaded
  • Switch the server's congestion control from CUBIC to BBR
  • Stop the window from shrinking on connections that sat idle
  • Change the number of packets in the first flight
  • Turn on FQ-CoDel in the home router
  • Make the router's buffer smaller
Try it yourself
0 of 8 correct

Sort each change by who can make it.

Choose a category for every card. You can change an answer at any time; Reset clears them all.

Common mix-ups

  • "A faster line fixes bufferbloat." No. A loss-based sender fills the buffer on a fast line too, and every packet still waits behind it.
  • "A bigger buffer makes the line faster." No. On both buffers, the download ran at the same speed. The big buffer only made round trips longer.
  • "The browser picks the congestion control for a page load." No. The side sending the bytes decides. For a page, that's the server.
  • "BBR keeps the buffer empty." No. It keeps a few round trips of data in flight at most. In the recording, round trips grew a little, not a lot.
  • "The 14 KB rule holds on every connection." No. It comes from TCP. On the course's QUIC server, the first flight carried less of the page than that.
  • "Only network engineers can do anything about this." No. A smaller first response, fewer connections and later big downloads all cut the round trips a page needs.

Practice exercises

Answer first, then use the hints.

Exercise 1 · Warm-upA faster line

Asha's line is upgraded to 20 Mbit/s. What does the last line print?

Starter codePop out in the code editor (opens in a new tab)JavaScript
// Asha's line: how many bytes are on their way during one round trip.
const megabitsPerSecond = 20;
const roundTripMs = 40;

const bytesPerMs = (megabitsPerSecond * 1_000_000) / 8 / 1000;
const lineFull = bytesPerMs * roundTripMs;
console.log(`${bytesPerMs} bytes leave every ms`);
console.log(`One round trip holds ${lineFull} bytes`);

Answer, then press Check. Spacing and letter case don’t matter.

    Exercise 2 · Warm-upHalf the buffer

    The router's buffer holds 256 packets, and it's full. What does it print?

    Starter codePop out in the code editor (opens in a new tab)JavaScript
    // A new packet joins the back of the buffer on Asha's line.
    const waiting = 256; // packets already in the buffer
    const packetBytes = 1378; // a 1,350-byte packet, plus 28 bytes of IP and UDP headers
    const bytesPerMs = 1250; // 10 Mbit/s
    
    const waitMs = (waiting * packetBytes) / bytesPerMs;
    console.log(`It waits ${waitMs.toFixed(1)} ms before it leaves`);

    Answer, then press Check. Spacing and letter case don’t matter.

      Exercise 3 · PracticeA bigger window before the loss

      The loss happened at a window of 200 packets. What does the second line print?

      Starter codePop out in the code editor (opens in a new tab)JavaScript
      // CUBIC after a loss, with RFC 9438's numbers. Windows count packets.
      const C = 0.4;
      const beta = 0.7;
      const wMax = 200; // the window when the loss happened
      const K = Math.cbrt((wMax - wMax * beta) / C); // seconds to grow back to wMax
      
      for (const t of [0, K]) {
        const cwnd = C * (t - K) ** 3 + wMax;
        console.log(`${t.toFixed(1)} s: ${Math.round(cwnd)} packets`);
      }

      Answer, then press Check. Spacing and letter case don’t matter.

        Exercise 4 · PracticeA 40 KB response

        Ravi's HTML is 40,000 bytes. What does the model print?

        Starter codePop out in the code editor (opens in a new tab)JavaScript
        // A model of the recorded rounds: the first flight carried 12,460 bytes
        // of the response, and each round after it carried about twice as much.
        function roundTrips(responseBytes) {
          let carried = 12460;
          let sent = carried;
          let rounds = 1;
          while (sent < responseBytes) {
            carried *= 2;
            sent += carried;
            rounds += 1;
          }
          return rounds;
        }
        
        for (const size of [40000]) {
          const n = roundTrips(size);
          console.log(`${size} bytes: ${n} round trip${n === 1 ? "" : "s"}`);
        }

        Answer, then press Check. Spacing and letter case don’t matter.

          Exercise 5 · ChallengeBBR on the small buffer

          In the senders playground, pick BBR with the small buffer. What was its largest window, in KB?

          Answer, then press Check. Spacing and letter case don’t matter.

            Exercise 6 · ChallengeFewer bytes on the wire

            Open the lesson's copy of Ravi's 60,000-byte page. In DevTools' Network panel, the page's transfer is far smaller than 60,000 bytes. Why?

            Answer, then press Check. Spacing and letter case don’t matter.

              Check your understanding

              For each question, ask yourself who sends the bytes, and where the extra waits.

              The congestion control quiz · 7 questionsScore: first tries count
              1. Question 1 of 7What does the CUBIC example print on its fourth line?

                Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
                // CUBIC after a loss, with RFC 9438's numbers. Windows count packets.
                const C = 0.4;
                const beta = 0.7;
                const wMax = 100; // the window when the loss happened
                const K = Math.cbrt((wMax - wMax * beta) / C); // seconds to grow back to wMax
                
                for (const t of [0, 2, K, 6, 8]) {
                  const cwnd = C * (t - K) ** 3 + wMax;
                  console.log(`${t.toFixed(1)} s: ${Math.round(cwnd)} packets`);
                }

                Choose an answer to see the explanation.

              2. Question 2 of 7On the big buffer, why did CUBIC's download make every round trip on Asha's line so much longer?

                Choose an answer to see the explanation.

              3. Question 3 of 7What does BBR use to decide how much to keep in flight?

                Choose an answer to see the explanation.

              4. Question 4 of 7Asha downloads the Mint tea page. Whose congestion control decides how fast its bytes come?

                Choose an answer to see the explanation.

              5. Question 5 of 7On the course's QUIC server, why did a 14 KB page need two round trips, when the 14 KB rule says it should fit in one?

                Choose an answer to see the explanation.

              6. Question 6 of 7A router's buffer is made much bigger. What happens to a long download and to everyone's round trips?

                Choose an answer to see the explanation.

              7. Question 7 of 7Which change can a frontend team make that cuts round trips for a visitor on a busy line?

                Choose an answer to see the explanation.

              Key takeaways

              • A sender can't see the line. Its congestion control decides how much to keep in flight.
              • The line holds its speed times its round trip, the BDP. Anything more waits in the router's buffer.
              • CUBIC grows until a packet is lost. On a big buffer, that means a nearly full buffer.
              • BBR measures the delivery rate and the shortest round trip, paces to match, and keeps only a few BDPs in flight.
              • Bufferbloat is the waiting a too-big buffer adds. It makes every round trip on the line longer.
              • A new connection starts with a first flight of 10 packets. Fit the first response in it, and reuse connections.

              Remember the one-liner.
              The sender guesses how much the line holds: CUBIC by losing packets, BBR by measuring, and a big buffer turns a bad guess into everyone's wait.

              Sources

              The facts on this page come from these standards, articles and source files:

              Coming next: HTTP prioritization internals. Once the bytes can flow, which response goes first? You'll see how servers and CDNs really order them.

              CompleteFrontend Clear concepts. Working examples.