VISUAL GUIDE · ONE-PAGE VERSION
Follow a web request
A shopper in Mumbai opens a product page and waits more than a second before anything appears. The app server is in Virginia, and the team keeps arguing about whether to buy bigger servers. Before changing anything, follow one request from the browser to the database and back, and write down where the time actually goes.
By the end you can
- Name the stages of a first page load: name lookup, connection setup, request, server work, response.
- Explain why a distant server costs time on every round trip, not just once.
- Spot a slow database query as server time that no network fix can remove.
- Say what a reused connection and a nearby edge each remove, and what they leave behind.
- Sketch a timing breakdown that points at the right fix before you pick one.
Assumptions behind the numbers
- Illustrative: user in Mumbai, app server in Virginia, about 200 ms for one round trip between them. Real numbers vary; measure your own.
- Illustrative: the DNS resolver is close to the user (about 20 ms away) and needs about 60 ms more to ask the authoritative server on a cache miss.
- Illustrative: TCP needs one round trip and TLS 1.3 needs one more before the first request can be sent. Older TLS versions need two.
- Illustrative: app code takes about 30 ms and one unindexed query takes about 400 ms; with an index the same query takes about 15 ms.
- Illustrative: a nearby edge is about 10 ms round trip from the user, and first visits through the edge still pay the same 80 ms DNS lookup. Transfer time for the HTML itself is ignored to keep the arithmetic simple.
STEP 1 OF 10 · SLOW PAGE
A page that feels slow
The shopper taps a link and stares at a blank screen for over a second. The only facts so far: the browser is in Mumbai and the server is in Virginia.
Resist the urge to name a fix. "Add a cache" and "buy a bigger server" fix different delays. The first job is to split that second into parts.
Why it matters. Most performance arguments end once someone writes down where the time goes. A design that guesses the cause often speeds up the wrong stage.
Where the time goesIllustrative · see assumptions
- DNS lookup (cache miss)80 ms
Total ≈ 80 ms
STEP 2 OF 10 · DNS LOOKUP
Find the address
The browser only knows the name shop.example, so it asks a DNS resolver (usually run by the ISP or a public DNS service) for an IP address. If the resolver has a fresh answer cached, this takes one short hop.
On a cache miss the resolver asks the authoritative DNS server for that domain, then caches the answer for as long as the record's TTL allows. Here that costs about 80 ms in total.
Why it matters. DNS is paid before anything else can start. It is usually small and cached, which is why it is worth knowing it exists rather than worth optimising first.
Where the time goesIllustrative · see assumptions
- DNS lookup80 ms
- TCP handshake (1 round trip)200 ms
Total ≈ 280 ms
STEP 3 OF 10 · TCP SETUP
Open a connection across the ocean
With an IP address in hand, the browser opens a TCP connection. The handshake needs a full round trip before any data can flow: a packet to Virginia and an answer back.
Nothing is slow here in the usual sense. The time is distance. Light in fibre plus routing between Mumbai and Virginia costs roughly 200 ms per round trip, and no server upgrade changes that.
Why it matters. Every round trip to a distant server costs the full distance again. Counting round trips is the quickest way to estimate network time.
Where the time goesIllustrative · see assumptions
- DNS lookup80 ms
- TCP handshake200 ms
- TLS 1.3 handshake (1 round trip)200 ms
Total ≈ 480 ms
STEP 4 OF 10 · TLS SETUP
Agree on encryption
HTTPS adds a TLS handshake on top of TCP. The two sides agree on keys and the browser checks the server's certificate. With TLS 1.3 that is one more round trip; older versions needed two.
So before the browser has asked for the page at all, it has spent about 480 ms: DNS plus two trips across the ocean.
Why it matters. Connection setup is a fixed cost per new connection. That is exactly what connection reuse and nearby edges attack later in this guide.
Where the time goesIllustrative · see assumptions
- DNS lookup80 ms
- TCP handshake200 ms
- TLS handshake200 ms
- Request travels (one way)100 ms
Total ≈ 580 ms
STEP 5 OF 10 · REQUEST SENT
The request reaches the server
Now the browser sends the HTTP request: GET /product/123 with headers such as cookies and accepted formats. It takes half a round trip, about 100 ms, to arrive.
The server can do nothing until those bytes land. Only now does "server time" start.
Why it matters. Splitting network time from server time tells you which team and which fix own the delay.
Where the time goesIllustrative · see assumptions
- DNS lookup80 ms
- TCP handshake200 ms
- TLS handshake200 ms
- Request travels100 ms
- App code30 ms
- Slow query400 ms
Total ≈ 1010 ms
STEP 6 OF 10 · SERVER WORK
The server builds the page, and waits on a query
The app code parses the request, checks the session and renders a template in about 30 ms. To fill in the product details it runs a SQL query.
That query filters on a column with no index, so the database scans far more rows than it returns. It takes about 400 ms, longer than any single network leg.
This is the delay no CDN or connection trick can remove for a personalised page. It needs an index, a cheaper query, or a cached result.
Why it matters. Server time is often hiding inside "the network is slow". One slow query can cost more than a trip across the ocean.
Where the time goesIllustrative · see assumptions
- DNS lookup80 ms
- TCP handshake200 ms
- TLS handshake200 ms
- Request travels100 ms
- App code30 ms
- Slow query400 ms
- Response travels100 ms
Total ≈ 1110 ms
STEP 7 OF 10 · RESPONSE
The response travels back
The server sends 200 OK with the HTML. The first bytes need another half round trip, about 100 ms, to reach Mumbai.
Add it up: roughly 1,110 ms before the browser can start drawing. About 600 ms is distance, 400 ms is one query, 80 ms is DNS and only 30 ms is the app code everyone wanted to rewrite.
Why it matters. With the full breakdown on paper, each fix has a number attached. Bigger servers would shave a few ms from the 30 ms slice.
Where the time goesIllustrative · see assumptions
- DNS, TCP, TLS (skipped)480 ms
- Request travels100 ms
- App code30 ms
- Slow query400 ms
- Response travels100 ms
Total ≈ 1110 ms
STEP 8 OF 10 · REUSE
The next request reuses the connection
When the shopper clicks to a second product a moment later, the browser still has the open, encrypted connection and a cached DNS answer. It skips DNS, TCP and TLS and sends the request straight away.
That removes about 480 ms. What remains is one round trip plus server work: about 630 ms, and the slow query is now most of it.
Why it matters. Keeping connections open (HTTP keep-alive, HTTP/2 multiplexing) is often the cheapest speed-up there is, but it only helps after the first request.
Where the time goesIllustrative · see assumptions
- DNS lookup80 ms
- TCP + TLS to edge20 ms
- Setup saved vs. Virginia380 ms
- Browser to edge and back10 ms
- Edge to server and back200 ms
- App code30 ms
- Slow query400 ms
Total ≈ 1120 ms
STEP 9 OF 10 · NEARBY EDGE
Put an edge near the user
Now route the shopper to an edge server in Mumbai. New connections are set up over a 10 ms hop instead of a 200 ms one, so TCP plus TLS drops from about 400 ms to about 20 ms.
The edge keeps a warm, already-encrypted connection to Virginia, so a personalised page pays the short hop to the edge (10 ms), one ocean round trip and the server time: about 740 ms on a first visit instead of 1,110.
If the response is the same for everyone (images, scripts, a public product page), the edge can cache it and answer in one 10 ms round trip without touching Virginia at all.
Why it matters. An edge removes connection setup distance for everyone and the whole trip for cacheable content. It does nothing for the slow query on uncached pages.
Where the time goesIllustrative · see assumptions
- DNS lookup80 ms
- TCP + TLS to edge20 ms
- Browser to edge and back10 ms
- Edge to server and back200 ms
- App code30 ms
- Indexed query15 ms
- Query time saved385 ms
Total ≈ 740 ms
STEP 10 OF 10 · FIX THE QUERY
Fix the server time too
The last big slice is the query. Adding an index on the filtered column turns a scan into a lookup, about 15 ms instead of 400.
With the edge and the index together, a first visit lands around 355 ms and a repeat click on the open connection around 255 ms. Either change alone still leaves you above 700 ms.
Why it matters. Network fixes and server fixes stack. The breakdown tells you to do both, and in which order, instead of debating one.
RECAP
What to remember
- A first page load pays for DNS, connection setup, the request, server work and the response, in that order.
- Distance is paid per round trip. TCP and TLS add round trips before the first byte of the request is sent.
- A reused connection skips setup; a nearby edge shortens setup for everyone and can skip the origin for cacheable responses.
- A slow query is server time. Only an index, a cheaper query or a cache removes it.
- Write the breakdown before choosing a fix, then attach a number to each fix.
NOW CLOSE THE GUIDE AND REDRAW IT
On a blank page, redraw the path from browser to database for a first visit. Label each stage, then mark where a slow database query adds time and where a distant server adds time. Finally, add a nearby edge and cross out the costs it removes.
Check your drawing against this list afterwards, not before:
- DNS lookup through a resolver, with the authoritative server only on a cache miss.
- TCP and TLS shown as round trips to the distant server before the request.
- Server work split into app code and the database query, with the slow query marked.
- The response path back to the browser.
- A nearby edge that shortens connection setup and keeps a warm connection to the origin.
- A note on what the edge cannot fix (the uncached slow query).
APPLY IT
Sketch a weather app
GO DEEPER WITH OUR GUIDES
OFF-SITE SOURCES · NOT WRITTEN BY US
Sources and further reading
- High Performance Browser Networking
Free book that explains latency, TCP, TLS and HTTP/2 from first principles. The chapters on TCP and TLS show where each round trip comes from.
- Populating the page: how browsers work
Walks through DNS, the TCP and TLS handshakes and the first response from the browser's point of view.
- RFC 8446: TLS 1.3
The protocol spec. Section 2 gives an overview of the full handshake and why 1.3 needs one round trip before application data.
- What is a CDN?
Short vendor explainer on how edge servers shorten distance and cache responses near users.