System Design HLD-00.02
What happens when you type a URL and press Enter
Follow one page load hop by hop: caches, DNS, TCP, TLS, HTTP, CDN, servers and rendering, and see where time goes and where things fail.
The big idea
Typing https://shop.example.com/cart and pressing Enter feels instant, but in that half second your browser holds a dozen conversations with machines around the world. It finds out where the shop lives, opens a connection, agrees on encryption, asks for the page, and then asks again for every image, script and font the page needs.
Every one of those steps is a place where time is spent, where a cache can skip the work, and where something can fail. Almost every topic in system design, from DNS to CDNs to databases, is about making one of these hops faster, cheaper or more reliable. This lesson walks the whole path once, so later lessons have a map to hang on.
Think of sending a letter to a company you have never written to. First you look up the address, then you check the post office will deliver there, then you seal the envelope so nobody can read it, and only then does the actual question go in the post. The answer comes back the same way.
How it works
Step 1: Read the URL
The URL is an instruction in parts:
httpsis the schemeThe protocol the browser should use. https means HTTP protected by TLS encryption.: use HTTP over an encrypted connection, on port 443 by default.shop.example.comis the hostnameThe human-readable name of the machine or service to contact, such as shop.example.com.: who to talk to./cartis the path: what to ask for. Anything after?is the query string, and anything after#stays in the browser.
Step 2: Check the caches first
Before going anywhere, the browser checks whether it already has what it needs. It may have the page itself in its HTTP cacheCopies of earlier responses the browser keeps, reused while the server's caching headers say they are still fresh., and it almost certainly has recent DNS answers cached. Skipping a step entirely is the biggest speed-up there is, which is why caching appears at every layer of every system.
Step 3: Walk the whole path
Here is the full journey for a first visit, with nothing cached. Press Next to move one hop at a time; the right margin shows typical times for a user on the same continent as the server.
- Where is shop.example.com? The resolver answers from its cache or walks the DNS tree: root, then .com, then example.com's own name server.
- It is 203.0.113.7 The answer comes back with a time to live, so the browser and resolver can reuse it for a while.
- TCP: SYN The browser opens a TCP connection with a three-way handshake: SYN, SYN-ACK, ACK. The address usually belongs to a nearby CDN edge server.
- SYN-ACK The edge answers. After the browser's ACK the connection is open, one round trip later.
- TLS: hello, keys TLS 1.3 agrees encryption keys and proves the server owns the name, using its certificate. One more round trip.
- GET /cart Now the real request goes out: method, path, headers and cookies, all encrypted.
- Not cached: forward A personal page like a cart cannot be cached at the edge, so the CDN forwards the request over a fast, already-open connection to the origin.
- auth, business logic A load balancer picks an app server. It checks the session, applies the business rules and decides what data it needs.
- SELECT cart items The app reads the cart from a cache or database, usually in the same data center, well under a millisecond away on the network.
- rows The data comes back and the app builds an HTML or JSON response.
- 200 OK + HTML The response travels back to the edge, which passes it on to the browser.
- 200 OK + HTML The first byte arrives. Time to first byte is one of the main numbers teams watch.
- GET css, js, images The browser parses the HTML, finds dozens of assets and requests them over the same connection. These are cacheable, so the edge answers directly.
- render the page The browser builds the layout, runs scripts and paints. The page becomes usable.
Three things stand out. First, several round trips happen before the request is even sent: DNS, TCP and TLS. That is why reusing connections and moving servers closer to users matter so much. Second, the CDN is the first stop, not the app: most bytes of most pages never reach your servers. Third, the database is only one hop out of many, even though it is where most design discussions focus.
Step 4: Where it can fail
Each hop has its own failure modes, and part of design is deciding what the user sees when one breaks:
Try it
Try this:
- For each step, estimate how many milliseconds it saves compared with not caching. Which saves the most?
- Which layers cannot help with a personal page like a shopping cart, and why?
- Pick one cache and think about what happens when the data it holds changes. You will return to this in the caching module.
Going deeper
Second visits are much faster
On a repeat visit, DNS is cached, the connection may still be open, and static files come from the browser cache. Only the personal parts of the page travel all the way to the origin. That is why first-visit performance and repeat-visit performance are measured separately.
Every hop gets its own lesson
DNS is covered in DNS in depth , TCP and packets in Networking basics: IP, TCP, UDP and ports , TLS in TLS and HTTPS and HTTP versions in HTTP/1.1, HTTP/2 and HTTP/3 . The orders of magnitude in the margin come from Latency numbers every engineer should know .
Trade-offs
| Option | Wins when | Loses when |
|---|---|---|
| Serve from a CDN edge | Static and public content: fast for everyone, offloads your servers | Personal or rapidly changing content that must not be shared or go stale |
| Keep connections open | Many requests from the same client: skips handshakes | Servers with limited memory facing many idle clients |
| Long cache lifetimes | Files that never change, such as versioned assets | Content that must update immediately for everyone |
Common mistakes
- Thinking a page load is one request. A typical page makes dozens of requests, and the slowest critical one sets the pace.
- Ignoring the handshakes. On a mobile network, DNS, TCP and TLS can cost more than the server's own work.
- Blaming the database first. Measure each hop; slow pages are often slow in the network or the browser.
- Forgetting certificates expire. Automate renewal, or one forgotten date takes the whole site down.
Check yourself
-
What does the browser need before it can open a connection to shop.example.com?
Show answer
B. An IP address, from DNS or its cache Connections go to IP addresses, so the hostname must be resolved first, unless the answer is already cached.
-
On a first visit, roughly how many round trips happen before the HTTP request is sent, after DNS?
Show answer
B. About two: TCP then TLS 1.3 The TCP handshake takes one round trip and TLS 1.3 another, so the request goes out after about two.
-
Why can't a CDN usually cache your shopping cart page?
Show answer
B. It is personal to you and changes often Shared caches must not serve one user's private data to another, so personal pages go to the origin.
-
Which hop is most often answered without reaching your servers?
Show answer
A. Requests for static assets like images and scripts Static assets are cacheable, so the browser cache or the CDN edge answers them.
Recap
- A page load is many hops: caches, DNS, TCP, TLS, HTTP, CDN, app servers and data stores.
- Several round trips happen before the request is even sent, so distance and connection reuse matter.
- Most bytes are served by caches and CDNs; only personal content reaches the origin.
- Every hop adds latency, can be cached and can fail.
- Later lessons zoom into each hop on this map.
Next up
- I know nothing yet learning path