What happens when you type a URL

System Design · lesson 17 of 32 · 4 min read

Follow one request from a hostname to HTML, and see where the milliseconds really go.

Open this lesson in the learning hub

Key points

  • The name is resolved first: OS cache, then the resolver, then the root and TLD servers, then the authoritative nameserver.
  • Answers are cached for the record TTL. A low TTL makes failover fast and costs you an extra lookup on most requests.
  • Then TCP: a three-way handshake, one round trip. TLS 1.3 adds one more on top of it; TLS 1.2 adds two.
  • Only then does the first GET go out. Cold, that is roughly four round trips before a single byte of HTML arrives.
  • Keep-alive and HTTP/2 reuse one connection for every asset, so the handshakes are paid once per visit, not once per file.
  • Anycast advertises one IP from many cities, so packets land at the nearest edge. That is how a CDN gets physically close to a user.

Example

# Which nameserver really answers, and what TTL it hands out.
dig +trace shop.example.com A | tail -3
# shop.example.com. 60 IN A 203.0.113.9      <- TTL 60: failover within a minute

# Where the time actually goes on one cold request.
curl -o /dev/null -s -w \
  'dns:%{time_namelookup} tcp:%{time_connect} tls:%{time_appconnect} ttfb:%{time_starttransfer}\n' \
  https://shop.example.com/
# dns:0.021 tcp:0.045 tls:0.092 ttfb:0.171    <- nothing cached, four round trips

# The next request on the same connection: DNS cached, socket and TLS reused.
# dns:0.000 tcp:0.000 tls:0.000 ttfb:0.038

# Cheapest wins available: keep-alive, HTTP/2, and a CDN edge near the user.
curl -sI --http2 https://shop.example.com/ | head -1
# HTTP/2 200

A cold request is mostly setup. Caching DNS and reusing connections removes three round trips of it.

This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the System Design course, and every lesson in it is listed on the System Design contents page.