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.7 What's the difference between TCP and UDP?
3 min read+10 XP
Under HTTP
In the restaurant: One waiter writes your order down, reads it back, and confirms; if a slip gets lost, they come back and ask again. Another just shouts orders across a noisy room: fast, but some orders are never heard.
In the system: HTTP rides on top of a transport protocol that actually moves the bytes.
Figure: TCP trades speed for guarantees. UDP trades guarantees for speed, and leaves the app to cope.
- TCP first sets up a connection with a three-way handshake (SYN, SYN-ACK, ACK). After that it guarantees every byte arrives, in order, resending anything lost. The cost: the handshake takes a round trip, and if one piece is lost, everything behind it waits until it's resent (head-of-line blocking).
- UDP just sends packets (datagrams). No handshake, no guarantee: packets can be lost, duplicated or arrive out of order. The app deals with it.
When each fits:
- TCP: anything that must be complete and exact. Web pages, APIs, file downloads, database connections.
- UDP: anything where late is as bad as lost. In a video call, a frame that arrives 2 seconds late is useless; better to skip it. Most DNS lookups use UDP because one tiny question and answer don't need a connection.
Memory code: "TCP confirms, UDP fires and forgets."