Where do the first 200 ms of a photo page actually go?
FotoFlow has 100 users and one server, and a user just said the feed feels slow. You cannot make anything faster until you know where the time goes, so let's follow one page load from Enter to pixels.
First: find the address
Networks route by number, not by name. So before anything else, the browser asks a DNS resolver: where is fotoflow.example? The answer, an IP address, comes back in about 20 ms.
DNS answers are cached with a time-to-live. For the next few minutes, repeat visits skip this step entirely. Free speed, nothing to build.
Second: open the line
The browser now connects to that IP. A TCP handshake agrees that both machines will talk. A TLS handshake on top adds encryption. Every web request is a conversation between machines, and each step costs time. Each handshake needs a round trip, a there-and-back.
Here a round trip is 30 ms, so connecting costs 60 ms before a single byte of the page is requested.
Third: ask, query, answer
Over the open connection the browser sends its request. The server parses it and calls your code. The photos do not live in the web server; they live in a database, so the server sends a query and waits for rows. That is one more round trip plus about 10 ms of real work. The server turns rows into HTML, and downloading the page takes another 20 ms. The browser renders.
The clock says 155 ms since Enter. Then the browser spots the images, stylesheets and scripts in the page, and fires off roughly 40 more requests. Reusing the already-open connection saves every one of them the handshake cost. Modern HTTP/2 pushes them all through that single connection at once.
Where the time actually went
Add it up. DNS, handshakes, request, response, download. Only about 25 of the 155 ms is your server actually working. The rest is the network. That changes what you optimize.
Two quick cases prove it. A new recommendation box ships, and its query sorts the whole photo table on every page view. The database takes 400 ms, and the page jumps past half a second. Same network, same handshakes. The fix is in the query, not the wires. Second case: same page, but opened from Sydney while the server sits in Virginia. Every round trip now costs 200 ms instead of 30. Two handshakes plus the request round trip burn 600 ms before download even starts. A round trip is set by distance and the network, not by how fast your server is.
What this does not solve
Knowing where time goes does not fix the two usual suspects. The slow query needs an index, which is its own post. The Sydney problem needs content closer to users, which is a CDN, also its own post. This post only gives you the map.
When your app felt slow last time, did anyone actually measure, or did everyone just upgrade something?
If a page loads in 155 ms but takes 555 ms for one user, is that a server problem or a geography problem?
Measure first, upgrade second.
Next in the series: Is your server slow, or is it just busy?
Sources
MDN: An overview of HTTP
Cloudflare: What is DNS?
Cloudflare: What is TLS?
Recommended for you
- Craft & Skills
One server, 10 million users: how does a photo app survive that?
A 40-post series that follows FotoFlow, a photo app, from one server and 100 users to 10 million users with direct messages. One problem, one fix, one honest cost at a time.
- Craft & Skills
Ten million users want direct messages: could you design the chat system?
The final design: 20 million open sockets and a promise that every message arrives, in order, exactly once. Dumb gateways, a connection registry, store-first durability and sync by cursor.
- Craft & Skills
Five million home feeds: how do you build the page everyone opens?
The home feed must load in 200 ms from two hundred followed accounts. Fan-out on read melts at 4.6 million lookups a second; fan-out on write melts on celebrities; the hybrid survives both.
- Craft & Skills
FotoFlow wants short share links: could you design one today?
The first full design walkthrough: turn a one-line brief into numbers, the simplest system, then fix codes, caching, storage and abuse one bottleneck at a time. The method is the point.
Enjoyed this article?
Subscribe for new articles. No spam. Unsubscribe anytime.
Typed live, never pasted.