Skip to main content
Client-Server Modellesson 2 of 4 · 2 min read

Before the First Byte

Four things happen before your code runs

Your code is the last thing that runs, not the first. Before it executes at all, the client pays for three separate setup ceremonies, and every one of them costs at least a full trip to another machine and back.

DNS goes first. Your browser asks a resolver, usually your provider's, to turn the hostname into an address. On a cold lookup that resolver walks a chain itself. It asks the root servers, then the servers for .com, then the one that authoritatively holds your record and returns the address. Caching makes the warm case nearly free, which is why every DNS record carries a time limit saying how long it may be reused.

Then comes the connection itself. Client and server exchange three small messages before a single byte of your data moves. That is one full round trip, so a server 100 milliseconds away has already cost you 100 milliseconds to send nothing at all.

Then encryption. The TLS handshake agrees on keys and checks the server's certificate, costing one or two more round trips depending on the version. Add all three together across a continent and a user can spend 300 milliseconds before your request has even left their machine.

Where the time actually goes

The protocol versions are all attempts to claw this back. HTTP/1.1 keeps the connection alive so many requests share one setup. HTTP/2 runs many streams over that single connection, though one lost packet still stalls all of them because the transport insists on delivering in order. HTTP/3 moves to a different transport that folds the connection and encryption handshakes together and lets streams lose packets independently. That last fix is most of why mobile-heavy sites moved to it.

the shape of it
DNS lookupresolver chainTCP handshakeSYN, SYN-ACK, ACKTLS handshake1-2 round tripsHTTP requestyour code runsIP foundconnectedencrypted
step 1 of 3
Three setup phases run in sequence before the application ever sees the request.

Worked example

Marcus runs a Shopify store and his customer Lena in Berlin loads it while the origin sits in Virginia, about 90 ms away. Cold visit, naive setup: DNS takes 50 ms, the TCP handshake 90 ms, TLS 1.2 adds two round trips for 180 ms. That is 320 ms of pure ceremony before the first HTML byte. Shopify's actual answer is a CDN edge in Frankfurt, 12 ms from Lena. The handshakes now happen against the edge: about 15 ms for DNS, 12 ms for TCP, 12 ms for TLS 1.3's single round trip. Setup drops from 320 ms to under 40 ms without touching a line of application code.