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:
- 1Root servers: "I do not know it, but the
.comservers are here." - 2`.com`: "Nor do I, but example.com's servers are here."
- 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:
GET /problems HTTP/1.1
Host: leetfoundation.com
Accept: text/htmlA response is a status, headers and a body:
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 4271| Status | Means | Whose fault |
|---|---|---|
| 200 | Fine | Nobody |
| 301 | Moved permanently | Nobody |
| 400 | Bad request | The client |
| 401 | Not signed in | The client |
| 403 | Signed in, not allowed | The client |
| 404 | No such thing | Usually the client |
| 500 | The server broke | The 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.