Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

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

2. Check caches

Before any network work the browser checks:

3. DNS lookup — name → IP address

The browser needs the IP of www.example.com. It checks, in order:

  1. Browser DNS cache
  2. Operating system cache (and the hosts file)
  3. Router cache
  4. 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 .com servers"
    • a TLD server (.com) → "ask example.com's name servers"
    • the authoritative server → "www.example.com is 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.

4. Getting packets out of your network

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)

  1. ClientHello: supported TLS versions and ciphers, a random value, and the SNI (hostname).
  2. ServerHello + certificate: the server picks a cipher and sends its certificate.
  3. The browser verifies the certificate: signed by a trusted Certificate Authority, not expired, hostname matches.
  4. Both sides do a key exchange (ECDHE) to create a shared symmetric session key.
  5. 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:

  1. CDN edge (Cloudflare, CloudFront) — may return a cached copy from a nearby city.
  2. Load balancer — picks a healthy server (Load Balancing).
  3. Reverse proxy / web server (Nginx) — TLS termination, compression, static files.
  4. Application server (Node/Express, Spring, Django) — runs middleware (auth, logging), the route handler, business logic.
  5. Cache (Redis) and database queries.
  6. 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

  1. Parse HTML → DOM tree.
  2. Finds <link>, <script>, <img> → fetches them (more requests, often in parallel over HTTP/2).
  3. Parse CSS → CSSOM. CSS is render-blocking.
  4. JavaScript: a normal <script> blocks parsing until downloaded and run; defer runs after parsing, async runs as soon as it downloads.
  5. DOM + CSSOM → render tree (only visible elements).
  6. Layout (reflow): compute each element's size and position.
  7. Paint: fill in pixels — text, colours, images, borders.
  8. 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

Interview one-liners

More Computer Networks notes