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.3 What happens when you type a URL and press Enter?
3 min read+10 XP
In the restaurant: Before you eat, a lot happens. You find the restaurant's address, walk in and get a table, check it's the real restaurant and not a fake, order, the kitchen cooks, and you eat.
In the system: Typing https://shop.example.com/books/42 sets off six steps. This is one of the most common interview questions, and it touches half this book.
Figure: the six steps from pressing Enter to seeing the page, and where each one is covered in this book.
- Find: the browser turns
shop.example.cominto an IP address using DNS (Chapter 4). It checks its own cache first. - Connect: it opens a connection to that IP address on port 443, with a TCP handshake (3.7). With HTTP/3 it uses QUIC instead (3.9).
- Secure: a TLS handshake checks the server's certificate and agrees on encryption keys (3.8).
- Ask: the browser sends the HTTP request
GET /books/42(3.4). - Answer: the request usually reaches a load balancer (Chapter 7), then an app server, which may check a cache (Chapter 12) and the database (Chapter 8). The server sends back a response.
- Show: the browser reads the HTML and starts rendering. It discovers more things it needs (CSS, JavaScript, images) and requests those too, often from a CDN (Chapter 26).
In an interview, say the steps in order, then go deep wherever the interviewer points.
Memory code: "Few Cooks Serve All And Smile." Find, Connect, Secure, Ask, Answer, Show.