What Happens When You Type a URL
"What happens when you type a URL into your browser and press Enter?" is one of the oldest interview questions in the industry, and it's still asked, sometimes as a warm-up, sometimes as a full system design round. It's popular because it has no bottom. A new grad can give a correct answer in two minutes. A senior engineer can spend forty minutes and still not cover everything: DNS caching, TCP congestion windows, TLS key exchange, anycast, CDN cache keys, connection pooling, the critical rendering path.
What your interviewer is really testing is whether you have a mental model of the whole stack, and whether you can go deep on demand without getting lost. The best answers do two things: give a crisp end-to-end outline first, then go deep wherever the interviewer steers, with real numbers.
We'll follow one request from keystroke to pixels, then put a latency budget on it:
- The browser decides what you typed and whether it even needs the network.
- DNS turns the hostname into an IP address.
- TCP and TLS (or QUIC) establish a secure connection.
- The request travels through the CDN and load balancer to an application server.
- The server builds a response.
- The browser turns the response into a page.
Step 1: The Browser Interprets What You Typed
Before anything touches the network, the browser has to decide what you meant.
- URL or search?
example.com/shoplooks like a URL;best pizza near medoesn't, so it goes to the default search engine. Browsers use heuristics (does it have a dot and no spaces? a known TLD? a scheme?) and the autocomplete list. - Parse the URL.
https://shop.example.com:443/cart?id=7#topsplits into a scheme (https), host (shop.example.com), port (443, the default for HTTPS), path (/cart), query (id=7) and fragment (#top). The fragment is never sent to the server; it's for the browser only. Non-ASCII hostnames are converted to punycode (xn--...) so DNS can handle them. - Upgrade to HTTPS. If you typed
example.comwith no scheme, modern browsers try HTTPS first. If the domain is on the browser's HSTS preload list, or previously sent aStrict-Transport-Securityheader, the browser refuses to use plain HTTP at all. This closes the window where a first plain-HTTP request could be intercepted. - Check local caches. A registered service worker for the origin can answer the request itself (that's how offline-capable web apps work). Otherwise the HTTP cache is checked: if a cached copy of the page is still fresh according to its
Cache-Control: max-age, the browser uses it with no network at all. If it's stale but has anETagorLast-Modified, the browser will send a conditional request and may get back a tiny304 Not Modified.
For a typical HTML page, the cache usually doesn't hold a fresh copy (HTML is often served with no-cache so users see updates), so we're going to the network.