Skip to content

hop 25 of 32 · 5 min

Names, and the protocol on top

Two application-layer protocols carry almost everything you do.

DNS

Resolving www.example.com with nothing cached walks down a hierarchy:

  1. 1Root servers: "I do not know it, but the .com servers are here."
  2. 2`.com`: "Nor do I, but example.com's servers are here."
  3. 3example.com's own server: "It is 93.184.216.34."

The resolver starts at the root because root addresses are the only ones it knows without asking: they ship as a hardcoded file.

In practice almost every step is cached, which is why this full walk is rare and why a DNS change takes hours to spread. Each record carries a TTL saying how long it may be cached, and that TTL is the delay.

HTTP

A request is a method, a path and headers:

code
GET /problems HTTP/1.1
Host: leetfoundation.com
Accept: text/html

A response is a status, headers and a body:

code
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 4271
StatusMeansWhose fault
200FineNobody
301Moved permanentlyNobody
400Bad requestThe client
401Not signed inThe client
403Signed in, not allowedThe client
404No such thingUsually the client
500The server brokeThe server

HTTP is stateless. Each request stands alone and the server remembers nothing between them. Cookies exist to work around exactly that: the server sends one, the browser returns it, and the server uses it to look up what it chose to remember.

Names, and the protocol on top