A page load feels instant, but it is really a chain of small conversations between machines. This post walks through one of them, hop by hop, and puts a number on every hop. The diagram follows along as you scroll.
How a Request Travels
Users say the shop feels slow
Someone on the team says the shop "feels slow". Before anyone can make it faster, we need to know where the time actually goes. The honest way to find out is to follow a single page load from start to finish.
You type shop.example and press Enter. About a sixth of a second later the page is on screen. Quite a lot happens in that gap, and almost none of it is your code running.
Find the address
Your browser knows a name, but packets travel to addresses. So the first thing it does is ask a DNS resolver: where does shop.example live? The resolver answers with an IP address.
One short question, one short answer across the network. From a home connection that is about 20 ms, and nothing else can start until it is done.
Open a connection
Now the browser knows where to go, but it cannot simply start talking. First it opens a TCP connection, then it negotiates TLS on top so that the conversation is encrypted.
Each of those is a round trip. On a typical home connection a round trip is roughly 30 ms, so the connection alone costs about 60 ms before a single byte of your page has been requested. Notice the resolver fading out: its answer is cached, so the next requests skip it.
Send the request
Over the open connection the browser finally sends GET /products. The server parses the request, checks the session and runs your code.
That is one more round trip plus about 10 ms of actual work on the server. For the first time in this story, your code is involved.
Fetch the data
The product list is not sitting in memory, so the server asks the database. The database usually lives in the same building, often in the same rack, so this hop is short.
The query hits an index and comes back in about 15 ms. Add it to the request and the server has now spent 55 ms in total.
The response comes back
The server turns the rows into about 110 KB of HTML and streams it back. Downloading that takes roughly 20 ms on a decent connection.
155 ms after you pressed Enter, the page is on screen. The connection stays open, which matters for what happens next.
More files, same story
The HTML references images, a stylesheet and some scripts. Each of them repeats the last three steps: request, maybe a database or disk read, response.
Nothing new happens, it just happens many times. Because the connection is already open, each extra file skips DNS and the handshakes. That is the single biggest reason connection reuse matters.
Case: one slow query
A new "recommended for you" box ships. Its query sorts every product by a score on every page view, and the database now needs 400 ms to answer.
Same network, same handshakes, same code everywhere else. Yet the page jumps from 155 ms to over half a second. Watch the request wait at the database: the network is innocent this time.
Case: a user in Sydney
Back to the fast query. Now the same page is opened from Sydney while the server sits in Virginia. Every round trip takes about 200 ms instead of 30.
Two handshake round trips plus the request round trip cost 600 ms before the page even starts downloading. Same server, same code, more than four times slower. Distance multiplies every wait.
Where the time went
Of 155 ms, only about 25 ms was a machine doing work. The other ~130 ms was messages crossing the network.
- DNS turns names into addresses, and the answers are cached.
- Connections cost round trips, so reuse them.
- Server code is often the smallest slice of latency, unless a slow query sneaks in.
- Distance multiplies every round trip.
Next up: the 15 ms database hop is paid by every visitor, and a cache can answer for most of them.