System Design HLD-01.05
HTTP/1.1, HTTP/2 and HTTP/3
Anatomy of an HTTP request, status codes, keep-alive, and how HTTP/2 multiplexing and HTTP/3 over QUIC fight head-of-line blocking.
The big idea
HTTPHyperText Transfer Protocol: the request and response protocol browsers, apps and APIs use to fetch and send data on the web. is the language of the web. A client sends a request ("GET me /cart"), the server sends back a response ("200 OK, here it is"). Every web page, mobile app API and most service-to-service calls speak it.
The messages have barely changed in 30 years. What has changed is how they are carried. A modern page needs dozens of files, and the way a protocol version moves many requests over the network decides whether the page appears in half a second or three. HTTP/1.1, HTTP/2 and HTTP/3 are three answers to the same question: how do you send many requests at once without one slow or lost response holding up the rest?
Picture a single-lane checkout. HTTP/1.1 is one cashier per lane, one customer at a time, and browsers open six lanes. HTTP/2 lets one cashier serve everybody's items interleaved, but if one item's barcode will not scan, the whole lane stops. HTTP/3 gives every customer an independent sub-lane, so a jammed scan only stops its owner.
How it works
Step 1: A request and a response
A request has a methodThe action requested: GET reads, POST creates, PUT replaces, PATCH updates part, DELETE removes., a path, headers and an optional body:
GET /cart HTTP/1.1
Host: shop.example.com
Accept: application/json
Cookie: session=8f3a...
The response has a status code, headers and a body:
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: private, max-age=0
{"items": [{"sku": "A12", "qty": 2}]}
Step 2: Status codes say what happened
The first digit tells the client what kind of outcome it got:
- 2xx success:
200 OK,201 Created,204 No Content. - 3xx redirect:
301 Moved Permanently,304 Not Modified(use your cached copy). - 4xx client error:
400 Bad Request,401 Unauthorized,403 Forbidden,404 Not Found,429 Too Many Requests. The client should change something before retrying. - 5xx server error:
500 Internal Server Error,502 Bad Gateway,503 Service Unavailable. The server failed; a retry later might work.
The difference between 4xx and 5xx matters in system design: retrying a 4xx is pointless, while 5xx errors are what your alerts and error budgets count.
Step 3: Three ways to carry many requests
HTTP/1.1 sends one request per connection at a time and waits for the full response before the next. Keep-aliveReusing one TCP connection for several requests one after another, instead of opening a new connection each time. reuses the connection, saving handshakes, but responses still queue. Browsers work around it by opening about six connections per host, each paying its own handshake and slow start.
HTTP/2 opens one connection and splits every request and response into small frames labelled by stream, then interleaves them. Dozens of requests are in flight at once, and repeated headers are compressed. But everything rides one TCP connection, and TCP delivers bytes in order. If one packet is lost, every stream waits for its retransmission, even streams whose data already arrived.
HTTP/3 keeps HTTP/2's ideas but runs over QUICA transport protocol built on UDP that provides reliable, encrypted, multiplexed streams; each stream is ordered on its own. on UDP. QUIC orders each stream separately, so a lost packet only stalls the stream it belongs to. QUIC also combines the transport and TLS handshakes, so a new connection is ready about one round trip sooner, and it can survive a phone switching from Wi-Fi to mobile data.
Try it
Try this:
- Start with HTTP/1.1 and no loss. See the staircase: six requests at a time, the rest queue.
- Switch to HTTP/2. All requests start together and the page finishes much sooner.
- Now lose a packet under HTTP/2. Every asset from 4 onward turns red: head-of-line blocking. Switch to HTTP/3 and only asset 4 waits.
The timings are illustrative, built from a 40 ms round trip, so read the shapes rather than the exact numbers.
Going deeper
Choosing status codes for an API
Return 201 with a Location header when you create something, 204 when there is nothing to return, 409 Conflict when a write clashes with the current state, 422 for valid JSON that fails validation, and 429 with a Retry-After header when rate limiting. Clients, proxies and monitoring tools all make decisions based on these codes, so being precise pays off. API design is covered in REST API design .
Who speaks what
Browsers and CDNs support all three versions and pick the best one both sides offer. Inside data centers, service-to-service traffic often uses HTTP/2 because gRPC is built on it, while networks are reliable enough that HTTP/3's benefits are smaller. HTTP/3 helps most on the lossy, changing networks of mobile users.
Trade-offs
| Option | Wins when | Loses when |
|---|---|---|
| HTTP/1.1 | Simplicity, debugging with plain text, very old clients and tools | Pages with many assets: requests queue and connections multiply |
| HTTP/2 | Many parallel requests over one connection on reliable networks, including gRPC | Lossy networks, where one lost packet stalls every stream |
| HTTP/3 (QUIC) | Mobile and lossy networks, fast connection setup, switching networks | Networks that block UDP, and environments where TCP tooling is required |
Common mistakes
- Returning
200 OKwith an error message in the body. Clients, caches and monitors then treat failures as success. - Retrying 4xx errors. The request is wrong; repeating it will not help. The exception is 429, which means "slow down", so wait as
Retry-Aftersays. - Still bundling everything into one giant file for HTTP/2. Multiplexing makes many small cacheable files cheaper than before.
- Assuming HTTP/2 removed head-of-line blocking. It removed it at the HTTP level, but TCP still has it.
Check yourself
-
A client sends a request with an invalid field. Which status family should the server return?
Show answer
C. 4xx The client made the mistake, so it is a 4xx, such as 400 or 422. Retrying unchanged will not help.
-
What is the main improvement of HTTP/2 over HTTP/1.1?
Show answer
B. Many requests interleaved over one connection HTTP/2 multiplexes many streams over one TCP connection and compresses headers.
-
On a lossy mobile network, why can HTTP/3 beat HTTP/2?
Show answer
B. A lost packet only blocks its own stream, not all streams QUIC orders each stream separately, so a loss no longer stalls every stream as TCP does.
-
What does a 503 Service Unavailable tell a client?
Show answer
C. The server cannot handle it right now; retrying later may work 5xx means a server-side failure. 503 specifically signals temporary overload or maintenance.
Recap
- HTTP requests have a method, path, headers and body; responses have a status, headers and body.
- 2xx success, 3xx redirect, 4xx client error, 5xx server error. 5xx (and 429) may succeed later; other 4xx will not.
- HTTP/1.1 queues one request at a time per connection; browsers open about six.
- HTTP/2 multiplexes streams over one TCP connection, but a lost packet still blocks them all.
- HTTP/3 runs over QUIC on UDP: independent streams and faster connection setup.
Next up
- I know nothing yet learning path