3. Client and Server
1
The picture to keep in your head2
3.1 What exactly are a client and a server?3
3.2 What's a request and a response?4
3.3 What happens when you type a URL and press Enter?5
3.4 What do GET, POST, PUT, PATCH and DELETE mean?6
3.5 What do status codes tell you?7
3.6 What goes in the headers and what goes in the body?8
3.7 What's the difference between TCP and UDP?9
3.8 How does HTTPS keep the conversation private?10
3.9 Why do keep-alive, HTTP/2 and HTTP/3 make things faster?11
3.10 What does "stateless" mean, and why do we want it?12
3.11 How do cookies, sessions and tokens remember who you are?13
Memory card and where the analogy breaks14
Practice: five levels15
Interview questions16
Solutions17
Sources18
Code lab3. Client and Server
3.5 What do status codes tell you?
3 min read+10 XP
In the restaurant: The waiter's reply tells you what happened: "here you go", "we moved, it's at the other branch", "that's not on the menu", or "sorry, the kitchen is on fire".
In the system: Every response starts with a three-digit status code. The first digit tells you the family:
| Family | Meaning | Common ones |
|---|---|---|
| 2xx | It worked | 200 OK, 201 Created, 204 No Content |
| 3xx | Look somewhere else | 301 Moved Permanently, 302 Found, 304 Not Modified (your cached copy is still good) |
| 4xx | The client made a mistake | 400 Bad Request, 401 Unauthorized (who are you?), 403 Forbidden (I know who you are; you can't), 404 Not Found, 409 Conflict, 429 Too Many Requests |
| 5xx | The server failed | 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout |
Pairs that trip people up:
- 401 vs 403: 401 means "you haven't proved who you are" (log in). 403 means "I know who you are, and you're not allowed".
- 502 vs 504: both come from something in the middle, like a load balancer. 502: the server behind it sent back a bad or broken response. 504: the server behind it didn't answer in time.
- 503: the server is overloaded or down for maintenance, and it's saying so.
Why it matters for design: clients and load balancers act on these codes. A 5xx may be worth retrying; a 4xx usually isn't, because sending the same bad request again gets the same answer.
Memory code: "2 is good, 3 go elsewhere, 4 your fault, 5 our fault."