What Happens When You Type a URL
The classic interview question answered end to end — URL parsing, DNS, TCP, TLS, HTTP, load balancers and servers, and how the browser renders the page.
"What happens when you type https://www.example.com into the browser and press Enter?" is one of the most popular interview questions because it touches almost every layer of the stack. There's no single right depth: start with the big picture, then go deep wherever the interviewer steers.
- Parse the input: is it a URL or a search? Scheme
https, hostwww.example.com, port 443, path/. - Check caches: HSTS list (force HTTPS), service worker, HTTP cache.
- DNS resolves the hostname to an IP.
- TCP connection (three-way handshake).
- TLS handshake: negotiate keys, verify the certificate.
- HTTP request sent; through CDN, load balancer, web server and application.
- Response comes back: status, headers, HTML.
- Browser renders: parse HTML, fetch subresources, build the DOM and CSSOM, lay out, paint.
1. The browser interprets the input
- No scheme and spaces? It's a search query.
- Otherwise it parses the URL:
scheme://host:port/path?query#fragment. The fragment is never sent to the server. - Internationalised domain names are converted to Punycode (
münchen.de→xn--mnchen-3ya.de). - If the domain is on the HSTS list (preloaded, or from an earlier
Strict-Transport-Securityheader),http://is upgraded tohttps://before any request leaves.
2. Caches first
A registered service worker may answer the request entirely from its cache. Otherwise the browser's HTTP cache may have a fresh copy (Cache-Control: max-age). It may also already hold an open connection to this host and can skip steps 3–5.
3. DNS resolution
Browser DNS cache → OS cache (and /etc/hosts) → recursive resolver (ISP, 1.1.1.1, or DoH) → root → .com → authoritative server. The answer may be a CNAME to a CDN, which then resolves to an edge server near you via geo-DNS or anycast. Details.
4. TCP connection
The OS picks an ephemeral source port and performs SYN → SYN-ACK → ACK with the server's port 443 — one round trip. Packets travel through your router (NAT), your ISP and across networks chosen by BGP, each router forwarding by longest-prefix match. ARP finds the gateway's MAC address for the first hop. TCP, Routing.
With HTTP/3, this step and the next are combined into a single QUIC handshake over UDP.
5. TLS handshake
The ClientHello includes SNI (www.example.com) and an ECDHE key share; the server answers with its key share and certificate chain. The browser verifies the chain to a trusted root, checks the hostname and validity, and checks the server's signature. Both sides derive session keys. One more round trip in TLS 1.3. HTTPS & TLS.
6. The request travels through the server side
GET / HTTP/2
:authority: www.example.com
accept: text/html
accept-encoding: gzip, br
cookie: session=...A typical modern path:
- The CDN may answer from cache, block attacks (WAF, DDoS protection) and terminate TLS.
- The load balancer picks a healthy backend (Load balancing).
- The app authenticates the session cookie, queries caches and databases, renders HTML (or the page is static or pre-rendered), and returns a response, possibly compressed with gzip/brotli.
7. The browser receives the response
The status code is checked (a 301/302 redirect starts over at the new URL). Headers set cookies, caching rules and security policies (CSP, HSTS). The body is decompressed and streamed to the HTML parser as it arrives.
8. Rendering the page
- Parse HTML → DOM. The preload scanner discovers CSS, JS, images and fonts early and fetches them in parallel (multiplexed over the same HTTP/2 connection).
- Parse CSS → CSSOM. CSS is render-blocking; synchronous
<script>tags block parsing (hencedefer,asyncandtype=module). - Render tree = DOM + computed styles for visible nodes.
- Layout (reflow): compute each box's position and size.
- Paint: fill pixels for text, colours, images, borders into layers.
- Composite: the GPU combines layers into the final frame.
- JavaScript runs, adds interactivity (hydration in frameworks like React) and may fetch more data.
Metrics that matter: Time to First Byte (TTFB), Largest Contentful Paint (LCP), Interaction to Next Paint (INP), Cumulative Layout Shift (CLS). See Browser rendering and Web performance.
Going deeper on request
Interviewers often dig into one area. Be ready to expand on:
- Networking: ARP and the first hop, NAT, BGP, congestion control and slow start.
- Security: certificate validation, HSTS, cookies (HttpOnly, SameSite), CORS, CSP.
- Back end: load-balancing algorithms, caching layers, database queries, horizontal scaling.
- Browser: event loop, critical rendering path, GPU compositing.
- OS: the keypress interrupt itself, system calls for sockets, the process model of a browser (one renderer process per site).
- Parse URL → caches → DNS → TCP → TLS → HTTP → server stack → response → render.
- Round trips dominate: DNS, TCP and TLS each cost RTTs; connection reuse, HTTP/3 and CDNs cut them.
- The server side is usually CDN → load balancer → reverse proxy → app → caches/DB.
- Rendering: DOM + CSSOM → render tree → layout → paint → composite; CSS and sync JS block it.