Frontend Labs
⋯

Chapter 27 — Latency, bandwidth, and bufferbloat

In one sentence

Bandwidth is how wide the pipe is; latency is how long it is — and for most things you actually notice, latency matters far more.

The two numbers, and the analogy

   BANDWIDTH  = how many lanes the motorway has
                (bits per second: 100 Mbit/s, 1 Gbit/s)

   LATENCY    = how long the motorway is
                (milliseconds: 5 ms, 90 ms, 600 ms)

A truck full of hard drives has enormous bandwidth and terrible latency. A phone call has tiny bandwidth and needs low latency.

Upgrading bandwidth does nothing for latency. Going from 100 Mbit/s to 1 Gbit/s does not make a website load 10x faster, because most of a page load is round trips (Chapter 4), not bytes.

Where latency comes from

   total delay =  propagation  +  serialisation  +  queueing  +  processing
Component Cause Can you fix it?
Propagation Distance ÷ speed of light in fibre (~200,000 km/s ≈ 5 µs per km) Only by moving closer — this is what CDNs do
Serialisation Time to clock the bits onto the wire: a 1500-byte packet takes 12 ms at 1 Mbit/s but 12 µs at 1 Gbit/s Faster links
Queueing Waiting behind other packets in a router's buffer Yes — this is the controllable one
Processing Routing lookups, NAT, encryption, VM overhead Better hardware, fewer hops

Physics floor: London to New York is ~5,600 km. Light in fibre does ~200 km/ms, so one way is ~28 ms, round trip ~56 ms minimum — and real paths aren't straight, so ~70–90 ms is typical. No amount of money makes that faster. Only moving the content closer does.

Bufferbloat: the one you can actually fix

Here's a problem you have probably experienced without knowing its name.

The symptom: when someone starts a big upload or download, everything else on the network becomes horrible. Video calls stutter, web pages crawl, games become unplayable — even though the download itself is going fine.

The cause: somewhere at the bottleneck (usually your home router or modem) there is a large, dumb buffer. TCP's congestion control (Chapter 25) increases speed until it sees loss — but with a huge buffer, packets aren't dropped, they're queued. So TCP keeps speeding up and fills the buffer, and now every packet — including your video call's, and your DNS lookups — has to wait behind a megabyte of bulk download.

   Idle:         ping = 20 ms
   During a big upload:  ping = 800 ms      <-- bufferbloat

How to test it (do this now — it takes 2 minutes):

# Terminal 1: watch latency continuously
ping 1.1.1.1

# Terminal 2: saturate your connection
curl -o /dev/null https://speed.cloudflare.com/__down?bytes=200000000
# and for the upload direction, use a speed test site

Watch the ping times in terminal 1. If they jump from 20 ms to hundreds of milliseconds, you have bufferbloat. Most home connections do.

Or use a browser test: waveform.com/tools/bufferbloat — it measures loaded vs unloaded latency and gives you a grade.

How to fix it: use Smart Queue Management (SQM) — a modern queueing algorithm (fq_codel or cake) at the bottleneck, which keeps the queue short and shares it fairly between flows.

  • Many consumer routers have an SQM or "bufferbloat" setting — turn it on.
  • OpenWrt has excellent SQM support.
  • On a Linux router: tc qdisc replace dev <wan> root cake bandwidth 90Mbit (set slightly below your real line rate, so the queue forms in the smart device rather than the dumb modem).

You typically give up ~5–10% of peak throughput and get a 10x improvement in latency under load. It's the single best network upgrade most people can make, and it's free.

Practice (25 min)

A. Measure your own physics:

ping -c 10 <your router>          # ~1 ms
ping -c 10 1.1.1.1                 # your ISP + a bit
ping -c 10 <something far away>    # distance

Divide the far one by 2 and multiply by 200 km/ms to estimate the fibre distance. Compare with a map. It's usually surprisingly close.

B. Do the bufferbloat test above. Record your idle and loaded latency in notes.md.

C. Prove bandwidth ≠ speed for web pages:

curl -w 'dns %{time_namelookup}  tcp %{time_connect}  tls %{time_appconnect}  ttfb %{time_starttransfer}  total %{time_total}\n' \
     -o /dev/null -s https://example.com

Notice how much of total happens before any content arrives. That portion is pure latency and is unaffected by your bandwidth.

D. Check your current queue discipline (Linux):

tc qdisc show

If it says pfifo_fast, you have a dumb FIFO queue. fq_codel or cake is what you want.

Common confusions

  • "I upgraded to gigabit but browsing feels the same." Correct, and expected. Browsing is latency-bound. You'd notice on large downloads.
  • "Bufferbloat is my ISP's fault." Usually the buffer is in your router or modem, which means you can fix it.
  • "More bandwidth fixes congestion." Only until it's used. Bufferbloat happens at any speed; it's about queue management, not capacity.

Check yourself

  1. What's the difference between bandwidth and latency?
  2. Why doesn't upgrading your connection speed make websites load much faster?
  3. What is bufferbloat and how do you test for it?
  4. Why does the fix involve deliberately shaping to below your line rate?

Further reading

  • Test: waveform.com/tools/bufferbloat — run it now.
  • Site: bufferbloat.net — the project that identified and named the problem.
  • Video: "Bufferbloat" — search for Jim Gettys' talks; he discovered it.
  • Article: "Latency Is Everywhere and It Costs You Sales" — a classic post on why latency matters commercially.
  • Book: High Performance Browser Networking — Ilya Grigorik. Free online at hpbn.co. Chapters 1–2 on latency and TCP are perfect follow-ups to Part 6. Highly recommended.

End of Part 6 — Milestone check

  • I can explain the sliding window and the window / RTT formula
  • I know why window scaling matters on long links
  • I can describe slow start and the congestion sawtooth
  • I know why parallel connections are faster on a lossy long path
  • I recognise the 40 ms fingerprint
  • I have tested my own connection for bufferbloat

Generated from real-life-guide-v1.md · 8 Oct 2026 16:36