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.
DNS end to end
Section titled “DNS end to end”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:
- Browser cache. Chrome keeps its own short-lived cache of lookups.
- 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.
- 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.
- 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.” - TLD servers. The
.inservers say: “example.inis handled by these authoritative name servers.” - 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.
Record types worth knowing
Section titled “Record types worth knowing”- A / AAAA — name → IPv4 / IPv6 address.
- CNAME — name → another name (“
wwwis an alias oflumen.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, briefly — and BGP
Section titled “IP, briefly — and BGP”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.
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.
Certificates and the chain of trust
Section titled “Certificates and the chain of trust”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.
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: from one lane to many
Section titled “HTTP: from one lane to many”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.
Headers and status codes that matter
Section titled “Headers and status codes that matter”You’ll meet these throughout the book:
Cache-Control,ETag,Last-Modified,Vary— caching (Chapter 6).Content-Encoding—gzip,br,zstdcompression.Content-Type— andX-Content-Type-Options: nosniff(Chapter 13).Set-Cookie/Cookie(Chapter 12).Strict-Transport-Security,Content-Security-Policy(Chapter 13).Link: <…>; rel=preloadand 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.
Reading the DevTools timing breakdown
Section titled “Reading the DevTools timing breakdown”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.
What you now know
Section titled “What you now know”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.
Self-quiz
Section titled “Self-quiz”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.
Exercises
Section titled “Exercises”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.