Notes › Computer Networks
What Happens When You Type a URL
The most famous networking interview question. Let's follow https://www.example.com/courses?page=2.
1. The browser parses the URL
https :// www.example.com :443 /courses ?page=2 #top
scheme host port path query fragment
- No scheme typed? The browser decides whether it's a search or a site and usually tries HTTPS.
- HSTS: if the site is on the HSTS list, the browser goes straight to HTTPS, never HTTP.
- The fragment (
#top) is never sent to the server.
2. Check caches
Before any network work the browser checks:
- Its HTTP cache — if a fresh copy exists (
Cache-Control: max-age), the page loads instantly. - A service worker may answer from its own cache.
3. DNS lookup — name → IP address
The browser needs the IP of www.example.com. It checks, in order:
- Browser DNS cache
- Operating system cache (and the
hostsfile) - Router cache
- ISP's recursive resolver (or 8.8.8.8 / 1.1.1.1), which, if it doesn't know, asks:
- a root server → "ask the
.comservers" - a TLD server (.com) → "ask example.com's name servers"
- the authoritative server → "
www.example.comis 93.184.216.34" The answer is cached according to its TTL. DNS normally uses UDP port 53. Details: DNS — The Internet's Phone Book.
- a root server → "ask the
4. Getting packets out of your network
- The OS sees the IP is not on the local network → send to the default gateway (your router).
- ARP finds the router's MAC address on the LAN.
- Your router does NAT (private IP 192.168.1.5 → its public IP) and forwards to the ISP; routers hop by hop move the packet toward the destination using routing tables (BGP between ISPs).
5. TCP connection — 3-way handshake
SYN → SYN-ACK → ACK with the server on port 443. Costs one round trip (RTT).
See TCP vs UDP and the 3-Way Handshake.
6. TLS handshake (HTTPS)
- ClientHello: supported TLS versions and ciphers, a random value, and the SNI (hostname).
- ServerHello + certificate: the server picks a cipher and sends its certificate.
- The browser verifies the certificate: signed by a trusted Certificate Authority, not expired, hostname matches.
- Both sides do a key exchange (ECDHE) to create a shared symmetric session key.
- Everything after is encrypted with that key (fast symmetric encryption like AES). TLS 1.3 needs just 1 RTT (0-RTT when resuming). With HTTP/3 (QUIC), TCP + TLS happen together over UDP.
7. Send the HTTP request
GET /courses?page=2 HTTP/2
Host: www.example.com
User-Agent: Mozilla/5.0 ...
Accept: text/html
Accept-Encoding: gzip, br
Cookie: session=abc123
8. On the server side
The request usually passes through:
- CDN edge (Cloudflare, CloudFront) — may return a cached copy from a nearby city.
- Load balancer — picks a healthy server (Load Balancing).
- Reverse proxy / web server (Nginx) — TLS termination, compression, static files.
- Application server (Node/Express, Spring, Django) — runs middleware (auth, logging), the route handler, business logic.
- Cache (Redis) and database queries.
- Builds the response (HTML or JSON).
9. The HTTP response
HTTP/2 200 OK
Content-Type: text/html; charset=utf-8
Content-Encoding: br
Cache-Control: max-age=300
Set-Cookie: theme=dark; HttpOnly; Secure
<!doctype html><html>...
Status codes: 2xx success, 3xx redirect (301 → browser repeats with the new URL), 4xx client error, 5xx server error. The connection is kept alive for more requests.
10. The browser renders the page
- Parse HTML → DOM tree.
- Finds
<link>,<script>,<img>→ fetches them (more requests, often in parallel over HTTP/2). - Parse CSS → CSSOM. CSS is render-blocking.
- JavaScript: a normal
<script>blocks parsing until downloaded and run;deferruns after parsing,asyncruns as soon as it downloads. - DOM + CSSOM → render tree (only visible elements).
- Layout (reflow): compute each element's size and position.
- Paint: fill in pixels — text, colours, images, borders.
- Composite: layers combined by the GPU and shown on screen. JavaScript then runs event handlers, fetches data (APIs), and updates the DOM (which can trigger reflow and repaint again).
Timeline at a glance
URL → cache? → DNS → TCP → TLS → HTTP request → CDN/LB/server/DB
→ HTTP response → HTML parse → CSS/JS → layout → paint → page visible
How to make it faster
- DNS prefetch /
preconnectto known hosts. - HTTP/2 or HTTP/3, keep-alive connections.
- CDN for static files, caching headers.
- Compress (gzip/Brotli), minify, lazy-load images and code.
deferscripts, inline critical CSS.
Interview one-liners
- Order: URL parse → cache → DNS → TCP handshake → TLS handshake → HTTP request → server → response → render.
- DNS: browser cache → OS → resolver → root → TLD → authoritative.
- TLS verifies the certificate and agrees on a symmetric key.
- Rendering: DOM + CSSOM → render tree → layout → paint → composite.
- Related: OSI and TCP/IP Models, HTTP and HTTPS.