Skip to content

5. How the Internet Delivers Your Bytes

“Bandwidth is how wide the road is. Latency is how far away your house is. Widening the road doesn’t move your house.”

The story: the post office and the phone book

Section titled “The story: the post office and the phone book”

Imagine sending a parcel to a friend in 1985. You know her name, not her address. So first you call directory enquiries: “What’s the address for Meera Iyer in Bengaluru?” The operator doesn’t know every address personally; she knows who to ask — the regional directory, which knows the city directory, which knows the street. You get the address. That’s DNS.

Then you post the parcel. It doesn’t travel as one object: the postal system breaks bulk shipments into sacks, routes each sack independently through sorting offices, and your friend reassembles them. Some sacks get lost; someone resends them. That’s IP (routing) and TCP (reliable delivery).

Before you send anything valuable, you’d like proof that “Meera” is really Meera, and you’d like the parcel sealed so postal workers can’t read it. That’s TLS.

And finally, the letter inside is written in a shared format: “Dear Meera, please send me your photo essay, kind regards.” That’s HTTP.

Every request your browser makes goes through all four. Each one adds round trips. On Priya’s phone, round trips are the most expensive thing in the universe.

Latency vs. bandwidth: the most important idea in this chapter

Section titled “Latency vs. bandwidth: the most important idea in this chapter”

Bandwidth is how much data per second a connection carries (Mbps). Latency is how long a single message takes to make a round trip (RTT, in milliseconds).

Marketing sells bandwidth. Web performance is dominated by latency, because loading a page is a conversation, not a download: look up the name (wait), open a connection (wait), negotiate encryption (wait), ask for HTML (wait), discover CSS and JS in it, ask for them (wait)…

On a fibre connection in a city, RTT to a nearby CDN might be 5–20 ms. On a decent 4G connection it’s often 50–100 ms. On a congested tower at 9 p.m., several hundred. Doubling bandwidth from 10 to 20 Mbps shaves almost nothing off a 50 KB HTML response; halving latency halves the cost of every single round trip.

Latency vs bandwidthTwo bars for fetching a 50 kilobyte file with 4 round trips at 80 milliseconds RTT. At 10 megabits per second: 320 milliseconds of latency plus 40 of transfer. At 20 megabits: 320 plus 20. The latency portion dominates both.10 Mbps4 round trips × 80 ms = 320 ms waiting4020 Mbpsstill 320 ms waiting2050 KB file. Doubling bandwidth saved 20 ms of 360. Halving RTT would save 160 ms.Moral: fewer round trips, and shorter ones (a CDN nearby), beat a fatter pipe.
Figure 5.1. Why latency dominates. Doubling bandwidth barely changes a small transfer; every round trip costs the full RTT regardless of size.

DNS maps names (lumen.example.in) to IP addresses (203.0.113.10). It is a distributed database with three properties you must understand: it’s hierarchical, it’s delegated, and it’s heavily cached.

The resolution path:

  1. Browser cache. Chrome keeps its own short-lived cache of lookups.
  2. OS stub resolver. The operating system’s resolver checks the hosts file and its own cache, then sends the question to a configured recursive resolver.
  3. Recursive resolver. Usually run by your ISP or mobile carrier, or a public one (Cloudflare’s 1.1.1.1, Google’s 8.8.8.8). It does the real work and caches everything it learns.
  4. Root servers. If the resolver knows nothing, it asks a root server, which doesn’t know the answer but knows who runs .in: “ask these TLD servers.”
  5. TLD servers. The .in servers say: “example.in is handled by these authoritative name servers.”
  6. Authoritative servers. They hold the actual records and answer: lumen.example.in A 203.0.113.10, TTL 300.

The resolver caches the answer for the TTL (time to live) — 300 seconds here — and the referrals for their own (typically much longer) TTLs. So in practice most lookups end at step 3 with a cache hit.

DNS resolution pathThe browser asks the OS stub resolver, which asks a recursive resolver. On a miss, the recursive resolver queries a root server, receiving a referral to the .in TLD servers; queries the TLD, receiving a referral to the authoritative name servers; and queries the authoritative server, receiving the A record with a TTL. The answer returns to the browser and is cached at each level.BrowsercacheOS stubhosts + cacheRecursiveresolvercaches by TTLRoot ( . ).in TLDAuthoritative1 “ask .in”2 “ask ns1…”3 A 203.0.113.10
Figure 5.2. DNS resolution. A cold lookup walks the tree root → TLD → authoritative; in practice the recursive resolver's cache answers most queries in one round trip.
  • A / AAAA — name → IPv4 / IPv6 address.
  • CNAME — name → another name (“www is an alias of lumen.example.in”). Can’t sit at the zone apex (bare domain) in standard DNS, which is why providers invented “CNAME flattening” / ALIAS records.
  • NS — which servers are authoritative for a zone.
  • MX — mail servers for the domain.
  • TXT — arbitrary text; used for domain verification (Search Console, certificate issuance) and email security (SPF, DKIM, DMARC).
  • HTTPS / SVCB — newer records that let a client learn, during DNS, that a server supports HTTP/3, saving a round trip of discovery.

“DNS propagation” is mostly a myth-ish phrase

Section titled ““DNS propagation” is mostly a myth-ish phrase”

People say “wait 48 hours for DNS to propagate,” as if changes flow outwards across the internet like ink in water. They don’t. Your authoritative server has the new record the instant you change it. What’s happening is caches expiring: every resolver that looked up your old record holds it until its TTL runs out. If your TTL was 86,400 seconds (a day), some resolvers will serve the old answer for up to a day.

The professional move: lower the TTL a day or two before a planned change (to, say, 300 seconds), make the change, verify, then raise it again.

IP delivers packets (chunks of up to roughly 1,500 bytes on most networks) from one address to another, hop by hop through routers, with no guarantees: packets can be lost, duplicated or reordered.

How do routers know where to send things? Networks (called autonomous systems — your ISP, Google, Cloudflare) announce to each other “I can reach these address ranges” using BGP, the Border Gateway Protocol. BGP is the internet’s map, built on trust between networks. When a big network withdraws its announcements, it vanishes from the map.

TCP: reliable delivery, at the price of round trips

Section titled “TCP: reliable delivery, at the price of round trips”

TCP turns IP’s unreliable packets into a reliable, ordered byte stream. It does this with sequence numbers, acknowledgements, and retransmission of lost packets. Three mechanisms matter for performance:

1. The three-way handshake. Before any data: client sends SYN, server replies SYN-ACK, client sends ACK (and can send data with it). That’s one round trip before the request can even be sent.

2. Slow start and the congestion window. TCP doesn’t know how fast the path is, so it starts cautiously. The server may only send a certain amount of data (the congestion window, cwnd) before waiting for acknowledgements. A common initial window is 10 packets — about 14 KB of payload. Each round trip without loss, the window roughly doubles: 14 KB, 28 KB, 56 KB, 112 KB… So a 100 KB response doesn’t arrive in one round trip; it takes several.

3. Loss recovery. When a packet is lost, TCP retransmits and shrinks its window, sometimes dramatically. On lossy mobile networks this is why “4G with full bars” can still feel sluggish.

The “14 KB rule” — and how true it is

Section titled “The “14 KB rule” — and how true it is”

From slow start comes the folk rule: “make your critical HTML fit in the first 14 KB, so it arrives in the first round trip.” There’s real logic to it: the first window is ~10 packets, and if the HTML’s <head> with critical CSS fits, the browser can start rendering after one round trip of data.

Caveats a senior engineer should know: compression means 14 KB on the wire can be 50 KB of HTML; TLS records and HTTP headers eat some of the window; servers may use larger initial windows; connection reuse means a warm connection has a bigger window already; and HTTP/3 has its own congestion control. Treat it as a useful direction — “keep the critical first chunk small, and put the important stuff early” — not a cliff edge at 14,600 bytes.

TCP slow startA client and server timeline. After the handshake, the server sends 10 packets (about 14 kilobytes) in round trip one, 20 packets in round trip two, 40 in round trip three. A 100 kilobyte response completes during round trip three.ClientServerSYNSYN-ACKACK + GETRTT 1: 10 packets ≈ 14 KBRTT 2: 20 packets ≈ 28 KB (total 42 KB)RTT 3: 40 packets ≈ 56 KB (total 98 KB)A 100 KB response needs ~3–4 round trips of data even on a fast link.
Figure 5.3. TCP slow start. The sender can only have a window of data in flight before waiting for acknowledgements; the window doubles each round trip. Small first responses arrive in one RTT; large ones take several.

UDP is IP with port numbers and nothing else: no handshake, no reliability, no ordering. Fire and forget. It’s used where speed matters more than perfection (video calls, games, DNS queries) — and, crucially, it’s what QUIC is built on, because building a new transport on top of UDP lets it be deployed in user space without waiting for every router and OS kernel on earth to upgrade.

TLS: proving identity and sealing the envelope

Section titled “TLS: proving identity and sealing the envelope”

TLS (the S in HTTPS) gives you three things: confidentiality (nobody on the path can read it), integrity (nobody can modify it undetected), and authentication (you’re talking to the real lumen.example.in).

TLS 1.3 (2018) completes its handshake in one round trip: the client sends its supported ciphers and a key share in its first message; the server replies with its key share, its certificate and a signature; both can derive the session keys. (TLS 1.2 needed two round trips.) For resumed sessions, 0-RTT lets the client send data immediately, with some replay caveats, so it’s used only for safe requests.

How does Priya’s phone know the server is really lumen.example.in? The server presents a certificate: a document saying “this public key belongs to lumen.example.in,” signed by a Certificate Authority (CA). The CA’s certificate is signed by a root CA. The phone ships with a list of trusted root CAs. If the chain of signatures leads from the server’s certificate up to a trusted root, and the server proves it holds the private key matching the certificate, the browser trusts it.

Certificate chainThree certificates left to right: the leaf for lumen.example.in signed by an intermediate CA, signed by a root CA. The root CA is in the device’s trust store, shown as a cylinder.lumen.example.inleaf certificateIntermediate CAsigns leafRoot CAsigns intermediatedevicetrust storesignssigns
Figure 5.4. The chain of trust. The server proves it holds the key in its certificate; signatures link that certificate to a root the device already trusts.

Let’s Encrypt made certificates free and automatic around 2016, which is why nearly all web traffic is now HTTPS. Certificate lifetimes keep shrinking, deliberately, so that automation is mandatory and a stolen key is useful for less time.

HTTP/1.1 (1997) is text: a request line, headers, a body. One request at a time per connection; the next waits for the previous response (head-of-line blocking at the application layer). Browsers worked around it by opening ~6 connections per host, and developers worked around that with sprites, concatenation and “domain sharding” — hacks whose ghosts still haunt old codebases.

HTTP/2 (2015) keeps the same semantics (methods, headers, status codes) but changes the wire format to binary frames on streams, multiplexed on a single connection. Many requests in flight at once, no need for six connections. Headers are compressed with HPACK (a big win: cookies and user agents repeat on every request). Domain sharding and concatenation became mostly unnecessary.

But one head-of-line problem remained, down in TCP. TCP delivers a single ordered byte stream. If one packet is lost, all streams on that connection wait for the retransmission, even those whose data arrived fine. On lossy mobile networks, HTTP/2’s single connection can actually behave worse than HTTP/1.1’s six.

HTTP/3 (standardized 2022) runs over QUIC, which lives on UDP and implements reliability per stream. A lost packet only stalls the stream it belongs to. QUIC also folds the TLS 1.3 handshake into the transport handshake — one round trip for a new connection, zero for resumed — and supports connection migration: when Priya’s phone switches from Wi-Fi to 4G, the connection survives because it’s identified by an ID, not by IP address and port.

HTTP/1.1 vs HTTP/2 vs HTTP/3HTTP/1.1: six parallel TCP connections each carrying one request at a time. HTTP/2: one TCP connection with interleaved streams; a lost packet marked in red blocks all streams. HTTP/3: one QUIC connection over UDP with independent streams; a lost packet only blocks its own stream.HTTP/1.1~6 TCP connections, one request each at a timeHTTP/2✗lost packet stalls ALL streams (TCP)HTTP/3stream 1 ✓stream 2 waits for its packetstream 3 ✓ (unaffected)
Figure 5.5. Three generations of HTTP. HTTP/2 multiplexed streams but kept TCP's single ordered pipe; HTTP/3 gives each stream its own loss recovery.

You’ll meet these throughout the book:

  • Cache-Control, ETag, Last-Modified, Vary — caching (Chapter 6).
  • Content-Encoding — gzip, br, zstd compression.
  • Content-Type — and X-Content-Type-Options: nosniff (Chapter 13).
  • Set-Cookie / Cookie (Chapter 12).
  • Strict-Transport-Security, Content-Security-Policy (Chapter 13).
  • Link: <…>; rel=preload and 103 Early Hints, which let a server tell the browser what to fetch before the HTML is ready.

Status codes: 200 OK. 301/308 permanent redirect (cached aggressively; affects SEO). 302/307 temporary. 304 Not Modified (revalidation said “your cache is fine”). 404 not found, 410 gone. 429 rate limited. 500 server error, 502/503/504 problems at or behind a proxy. Every redirect is at least one extra round trip — Priya pays 80 ms for http:// → https:// → https://www. → final page.

Click any request in the Network panel and open Timing. The phases map exactly onto this chapter:

  • Queueing — the browser hasn’t started yet: lower priority, waiting for a connection slot, or the main thread was busy.
  • Stalled — waiting before sending, e.g. for a connection to free up or a proxy.
  • DNS Lookup — Section 2.
  • Initial connection — the TCP (or QUIC) handshake.
  • SSL — the TLS handshake (part of initial connection).
  • Request sent — usually tiny.
  • Waiting for server response (TTFB) — from request sent to first byte back: network latency plus server think-time. If this is big, ask whether the server is slow or the server is far away.
  • Content Download — receiving the body. Big for large files on slow links.
Request timing waterfallA horizontal bar split into labelled phases: queueing, stalled, DNS lookup, initial connection with SSL inside it, request sent, waiting for server response (TTFB), and content download. Below, a second bar for a reused connection shows only request sent, waiting and download.QueueStalledDNSTCPSSLWaiting (TTFB): RTT + server timeContent DownloadReused connection:no DNS, no handshakes
Figure 5.6. One request's timing, labelled. Reused connections skip DNS, connect and SSL entirely — a big reason a CDN and connection reuse matter.

You can walk DNS from stub resolver to authoritative server and explain TTLs and “propagation”; describe TCP’s handshake, slow start and what’s true about the 14 KB rule; explain TLS 1.3 and the chain of trust; compare HTTP/1.1, /2 and /3 by where head-of-line blocking lives; and read every phase of a DevTools timing breakdown. That’s the vocabulary of every networking conversation you’ll have as a senior engineer.

1. Why does halving RTT usually beat doubling bandwidth for page loads?

Page loads are chains of round trips with mostly small payloads; each RTT is paid in full regardless of size.

2. What actually happens during “DNS propagation”?

Resolvers’ cached copies of the old record expire according to its TTL.

3. What head-of-line blocking does HTTP/2 not solve?

TCP-level: one lost packet stalls all multiplexed streams on the connection.

4. How many round trips does a fresh HTTPS connection cost over TCP + TLS 1.3? Over QUIC?

About two (TCP + TLS) before the request; about one with QUIC (combined), zero on resumption.

5. A request shows 900 ms “Waiting (TTFB)”. What two things could it be?

Network latency to the server (far away/slow network) and server processing time (slow rendering, database). Compare with a request to a nearby static file to separate them.

Warm-up 1. Count the round trips. A first visit to http://lumen.example.in redirects to https://www.lumen.example.in. On HTTP/2 over TCP+TLS 1.3 with a cold DNS cache (assume one DNS RTT per name), how many RTTs before the HTML’s first byte?

Solution

DNS (1) + TCP (1) + request (1) for the redirect; then DNS for www (1) + TCP (1) + TLS (1) + request (1). About 7 RTTs — over half a second at 80 ms. Use HSTS preload and link directly to the canonical URL.

Warm-up 2. TTL planning. You’re moving Lumen to a new server next Tuesday. Your A record TTL is 86400. What do you do and when?

Solution

By Sunday, lower TTL to 300; wait a day for old caches to expire; switch on Tuesday; verify; raise TTL again afterwards.

Warm-up 3. Read the timing. Two images on the same page: one shows DNS + Initial connection + SSL, the other doesn’t. Why?

Solution

The second reused the connection opened by the first (same origin), skipping handshakes. Different origins cost new connections — a reason to self-host critical assets.

Lab 4. Trace a lookup. Use a DNS lookup tool with tracing to follow lumen’s (or any) domain from root to authoritative. Note the TTLs at each level.

Expected outcome

Root and TLD referrals have long TTLs (days); your record has whatever you set. That asymmetry is why most lookups end at the resolver.

Lab 5. Protocol check. In DevTools, enable the Protocol column on the Network panel and load Lumen and three big sites. Which use h2, which h3?

Hint

HTTP/3 often appears only on a repeat visit, after the browser learns via Alt-Svc or HTTPS records that the server supports it.

Lab 6. Feel latency. Load Lumen with DevTools network throttling at a “Slow 4G”-style preset. Note how the waterfall stretches even for tiny files.

What to notice

Small files take nearly the full RTT. Requests discovered late (by JS) are the most expensive. You’ll fix these in Chapters 9 and 18.

Staff 7. Explain TTFB. A PM says “our TTFB in India is 1.2 s, the backend team says the server responds in 80 ms. Who’s lying?” Write the explanation.

Model answer

Nobody: TTFB includes DNS, connection setup, TLS and round trips to a server that may be in another continent, plus server time. 80 ms is server time; the rest is distance and handshakes. Fix with a CDN/edge near users, connection reuse, and caching HTML at the edge.

Staff 8. DNS as a dependency. Write a short risk assessment of your product’s DNS: who hosts it, what happens if they’re down, how TTLs affect failover, and who can change records.

Model points

Single-provider risk, registrar account security (2FA, lock), TTL vs failover speed trade-off, change review for DNS like any deploy, monitoring resolution from multiple regions.