The Fast Lane: Networking Fundamentals
A deep-dive into the invisible infrastructure beneath every web app. Understand why that extra 50ms costs you users, how TCP's three-way handshake burns your first RTT, and why TLS 1.3 was such a big deal.
Every millisecond matters. Not in a motivational-poster way — in a your users are leaving way. Google found that a 400ms slowdown reduced searches by 0.44%. Amazon calculated that every 100ms of latency costs them 1% of sales. These aren't abstract statistics — they're the business case for understanding what actually happens between your user clicking and your app responding.
This series is a structured walkthrough of Ilya Grigorik's High Performance Browser Networking — one of the most technically dense and practically useful books ever written about web performance. We'll make it interactive, visual, and immediately applicable.
Let's start at the bottom of the stack.
Chapter 1: The Physics of Speed
Before we can optimize anything, we need to understand why the web is slow by default. And that reason is, embarrassingly, the speed of light.
Latency is the killer
Latency is the time it takes for a packet to travel from source to destination. It's measured in milliseconds and breaks down into four components:
- Propagation delay: Time for signal to travel through the medium (governed by physics)
- Transmission delay: Time to push all packet bits onto the wire (governed by bandwidth)
- Processing delay: Time for routers to examine and route the packet
- Queuing delay: Time waiting in router buffers (governed by traffic)
Of these, propagation delay is the fundamental floor — you can't go faster than light.
The speed of light problem
Light travels at 299,792 km/s in a vacuum. But fiber optic cables slow it down to roughly 200,000 km/s (about two-thirds of c) because light refracts as it bounces through the glass.
This creates a hard physical ceiling on how fast data can travel:
| Route | Distance | Min RTT |
|---|---|---|
| New York → San Francisco | 4,130 km | ~41ms |
| New York → London | 5,570 km | ~56ms |
| New York → Tokyo | 10,838 km | ~108ms |
| New York → Sydney | 16,232 km | ~162ms |
These are theoretical minimums. Real-world RTTs are 30-50% higher due to routing overhead, processing delays, and the fact that submarine cables don't travel in straight lines.
<LatencyCalculator />Bandwidth vs. Latency
A common mistake: assuming bandwidth is the bottleneck. For most web requests, latency dominates bandwidth because:
- Most web payloads are small (JSON API responses, HTML fragments)
- Bandwidth keeps increasing (5G, fiber to home)
- Latency improvements are physically constrained
Think of it this way: you can widen a highway all you like, but if London is 5,000km away, the cars still take 25ms to arrive.
<CalloutBox type="fun" title="The Speed of Light Is Fixed, But RTT Isn't"> Real-world RTT from New York to London is ~75ms — almost 35% higher than the theoretical minimum of 56ms. That gap is engineers optimizing routing protocols, building more geographically distributed CDN nodes, and running anycast DNS. Physics gives you the floor; engineering determines how close you get. </CalloutBox>Last-Mile Latency
The "last mile" — the connection between ISP and your home — is often the worst bottleneck. A transatlantic fiber cable carries packets at close to c, but your cable modem or DSL connection might add 10-50ms of its own.
Mobile networks make this worse: 4G LTE adds 30-50ms, older 3G networks add 100-500ms. We'll cover wireless in Part 2.
Chapter 2: TCP — The Reliable Workhorse
TCP (Transmission Control Protocol) is the reason you can download a file reliably, but also the reason your first HTTP request feels slow. Understanding TCP's mechanics is essential for any web performance work.
What TCP gives you
TCP provides:
- Reliable delivery: Every byte arrives, or the connection errors
- Ordered delivery: Bytes arrive in the sequence they were sent
- Error checking: Corrupted packets are retransmitted
- Flow control: Prevents fast sender from overwhelming slow receiver
- Congestion control: Backs off when the network is congested
All of this comes at a cost: setup overhead.
The Three-Way Handshake
Before a single byte of application data can flow, TCP must complete a handshake to synchronize sequence numbers between client and server. This costs one full round-trip time before data flows.
<TCPHandshake />The handshake sequence:
- SYN: Client picks a random sequence number and sends it to the server
- SYN-ACK: Server acknowledges, picks its own sequence number
- ACK + DATA: Client confirms and can now send application data
This means: every new TCP connection burns one RTT before your app gets a chance to send anything. On a 75ms transatlantic connection, that's 75ms wasted just establishing the connection.
TCP Slow Start
Here's where TCP gets interesting (and frustrating). Even after the handshake, TCP doesn't immediately use the full available bandwidth. It starts conservatively and probes for capacity.
The algorithm is called Slow Start:
- Start with a congestion window (cwnd) of ~14KB (10 segments of 1460 bytes)
- For each ACK received, increase cwnd by one segment
- This doubles cwnd every RTT (exponential growth)
- When a packet is lost, cwnd is cut in half (or reset)
The practical implication: small transfers may never exit slow start. An HTTP response of 64KB would require:
- RTT 1: Send 14KB
- RTT 2: Send 28KB
- RTT 3: Send 64KB (all transferred)
On a 75ms connection, that's 225ms of transfer time just to send 64KB — even with 100Mbps of available bandwidth.
<CodePlayground title="Simulating TCP Slow Start" language="javascript" code={`// Simulate TCP slow start behavior function simulateSlowStart(targetBytes, initialCwnd = 14000, rttMs = 75) { let cwnd = initialCwnd; let bytesTransferred = 0; let rttCount = 0; const log = [];
while (bytesTransferred < targetBytes) { const sent = Math.min(cwnd, targetBytes - bytesTransferred); bytesTransferred += sent; rttCount++; log.push(`RTT ${rttCount}: sent ${(sent/1024).toFixed(1)}KB, total ${(bytesTransferred/1024).toFixed(1)}KB`); cwnd *= 2; // Exponential growth during slow start }
console.log(log.join('\n')); console.log(`Total time: ~${rttCount * rttMs}ms`); }
simulateSlowStart(200000); // 200KB payload`} />
Connection Reuse and Keep-Alive
Because new TCP connections are expensive (1 RTT + slow start), HTTP/1.1 introduced persistent connections (Keep-Alive). The TCP connection stays open between requests, avoiding the handshake overhead.
Best practices:
- Reuse connections (HTTP/1.1 does this by default)
- Minimize the number of distinct TCP connections
- Use connection pooling in server-to-server communication
TCP Fast Open
TCP Fast Open (TFO) lets clients attach data to the SYN packet on repeat connections, eliminating the handshake RTT. The trick: on the first connection, the server sends a cryptographic token. On subsequent connections, the client includes this token and data in the SYN.
TFO can save one full RTT on repeat connections — significant on high-latency links.
<Quiz question="A user in Tokyo connects to a New York server (~110ms RTT) for the first time over HTTPS. How many RTTs pass before they see any response data, assuming TLS 1.3?" options={[ "1 RTT (TCP handshake only)", "2 RTTs (TCP + TLS 1.3)", "3 RTTs (TCP + TLS 1.3 + HTTP request/response)", "4 RTTs (TCP + TLS 1.2 standard)" ]} correct={2} explanation="A cold HTTPS connection requires: 1 RTT for TCP three-way handshake, 1 RTT for TLS 1.3 handshake, then 1 RTT for the HTTP request + response. Total: 3 RTTs = ~330ms before data arrives. This is why CDNs, HTTP/2, and connection reuse matter so much." />
Chapter 3: UDP — When Speed Beats Reliability
TCP's reliability comes with overhead. For some applications, you'd rather drop packets than wait for retransmission. That's where UDP (User Datagram Protocol) comes in.
What UDP Sacrifices
UDP provides:
- No handshake: Send immediately
- No delivery guarantee: Packets may be lost
- No ordering: Packets may arrive out of order
- No congestion control: Send as fast as you want (danger!)
In exchange, you get:
- Zero connection setup latency
- Lower per-packet overhead (8-byte UDP header vs. 20-byte TCP header)
- Control over reliability trade-offs at the application layer
When UDP Wins
UDP is the right choice when:
-
Real-time communication matters more than completeness: Video calls, gaming, live audio. A dropped frame in a video call is invisible; a 200ms retransmission delay is very visible.
-
You can implement smarter reliability than TCP: QUIC (the protocol behind HTTP/3) uses UDP but adds its own reliability with better congestion control than TCP.
-
Broadcast/multicast: UDP supports one-to-many delivery naturally.
-
Tiny, fire-and-forget messages: DNS queries, DHCP, network discovery.
UDP + Application-Layer Reliability = QUIC
The most exciting development in modern networking is QUIC (Quick UDP Internet Connections), now standardized as HTTP/3's transport layer.
QUIC takes UDP's low overhead and adds:
- Stream multiplexing without head-of-line blocking
- 0-RTT connection establishment on repeat visits
- Connection migration (switch from WiFi to 4G without reconnecting)
- Improved congestion control
We cover QUIC in depth in Part 3.
Chapter 4: TLS — Security in Every Byte
In 2024, TLS is non-negotiable. HTTPS is the baseline for any serious web app, and understanding TLS performance overhead is critical for developers who care about speed.
What TLS Provides
TLS (Transport Layer Security) provides three guarantees:
- Encryption: No eavesdropping on the wire
- Authentication: You're talking to who you think you are
- Integrity: Data hasn't been tampered with in transit
These properties are delivered through a cryptographic handshake that, historically, added significant latency overhead.
The TLS Handshake Overhead
<TLSHandshake />TLS 1.2 (still common as of this writing) requires 2 additional RTTs on top of TCP's 1 RTT. That means a cold HTTPS connection costs 3 RTTs before any application data flows.
TLS 1.3 (RFC 8446, 2018) reduced this to 1 RTT by restructuring the handshake:
- Client sends its key share in the first message
- Server can send encrypted data in its first response
0-RTT Session Resumption
TLS 1.3 also introduced 0-RTT resumption for returning clients. The server issues a "session ticket" that the client can use on the next connection to start sending application data immediately — before the handshake completes.
Important caveat: 0-RTT data is replay-vulnerable. An attacker could record a 0-RTT request and replay it later. For this reason, 0-RTT is only appropriate for safe, idempotent operations (GET requests). Never use 0-RTT for POST/PUT/DELETE.
<CodePlayground title="Checking TLS Version and Cipher in Node.js" language="javascript" code={`const https = require('https');
https.get('https://example.com', (res) => { const socket = res.socket; console.log('TLS version:', socket.getProtocol()); console.log('Cipher:', socket.getCipher()); // Output: TLS version: TLSv1.3 // Output: Cipher: { name: 'TLS_AES_128_GCM_SHA256', standardName: '...', version: 'TLSv1/SSLv3' } });`} />
Cipher Suite Performance
Modern TLS uses AEAD (Authenticated Encryption with Associated Data) ciphers:
- AES-128-GCM: Widely supported, hardware-accelerated on modern CPUs
- ChaCha20-Poly1305: Faster on mobile CPUs without AES hardware acceleration
TLS 1.3 mandated removing weak cipher suites, making it both more secure and simpler to implement correctly.
Certificate Validation
Every TLS connection must validate the server's certificate:
- Check the certificate is signed by a trusted CA
- Verify the certificate hasn't expired
- Check OCSP (Online Certificate Status Protocol) for revocation
OCSP stapling allows servers to include a pre-fetched revocation status in the TLS handshake, eliminating an extra round-trip for certificate validation.
<Quiz question="TLS 1.3 introduced 0-RTT resumption. Which type of request is UNSAFE to send as a 0-RTT request?" options={[ "GET /api/articles (fetch a list)", "POST /api/checkout (place an order)", "GET /api/user/profile (read profile)", "GET /images/logo.png (fetch a static asset)" ]} correct={1} explanation="0-RTT requests are replay-vulnerable. A POST /api/checkout could be replayed by an attacker to place duplicate orders. Only idempotent, safe requests (like GETs) should use 0-RTT. The HTTP spec defines safe methods as those with no side effects." />
Key Takeaways
After these four chapters, you should have a clear mental model of why the web has latency floors and how protocols try to work around them:
- Physics sets the floor: ~200,000 km/s in fiber = minimum propagation delay
- TCP's handshake costs 1 RTT: Before any data on a new connection
- TLS adds 1 RTT more (TLS 1.3) or 2 RTTs (TLS 1.2): So cold HTTPS = 3 RTTs minimum
- Slow start limits throughput: Small responses may be bandwidth-constrained even on fast links
- UDP enables real-time: At the cost of reliability your app must manage
- QUIC is the future: UDP + application-layer reliability, now shipping as HTTP/3
- Enable TLS 1.3 on your web server (nginx, Caddy, or your CDN)
- Use HTTP/2 or HTTP/3 to share connections across requests
- Deploy a CDN to reduce propagation distance to users
- Enable OCSP Stapling to eliminate certificate validation round-trips
- Audit your DNS TTL — long TTLs reduce lookup overhead </CalloutBox>
Up Next: Part 2 — Wireless Networks
Part 2 dives into the performance characteristics of WiFi and mobile networks. If you thought wired networks were constrained, wait until you see the math on radio bandwidth, interference, and the mobile network stack.