Networking

HTTP/1.1 vs HTTP/2 vs HTTP/3

What each HTTP version fixed, where head-of-line blocking moved each time, and which version to use on each hop of a design.

Lesson13 min read
Video walkthrough: not recorded yet. The lesson below is complete without it.

The problem

In HTTP/1.0, as documented in 1996, every request used its own TCP connection: connect, send one request, read one response, close. A page then was an HTML file and a few images, so nobody minded.

Pages grew. A typical page today loads dozens of resources, and often more than a hundred: scripts, stylesheets, fonts, images, API calls. Each new connection costs a round trip for the TCP handshake, more for TLS, and starts with a small congestion window. On a link with a 100 ms round trip, a hundred sequential connections spend over ten seconds on handshakes alone.

HTTP/1.1 introduced persistent connections, but engineers still spent most of the next two decades working around one limit. They opened several connections in parallel. They split assets over hostnames such as static1 and static2 to get more connections. They glued scripts into bundles and icons into sprite sheets so there were fewer things to fetch. Each of these is a workaround for the same fact: an HTTP/1.1 connection carries one request at a time. HTTP/2 and HTTP/3 are the two attempts to fix it properly.

Three requests on HTTP/1.1, HTTP/2 and HTTP/35 components: Browser, HTTP/1.1, HTTP/2, HTTP/3, Server. Connections: Browser to HTTP/1.1; HTTP/1.1 to Server; Browser to HTTP/2; HTTP/2 to Server; Browser to HTTP/3; HTTP/3 to Server.Browser2 requests waitingHTTP/1.1one request at a timeHTTP/2streams on one TCP connectionHTTP/3streams on QUIC over UDPServer

Step 1 of 9

An HTTP/1.1 connection carries one request at a time. The browser asks for the stylesheet, and its requests for the script and the image wait until that whole response has come back.

Read the steps as text
  1. An HTTP/1.1 connection carries one request at a time. The browser asks for the stylesheet, and its requests for the script and the image wait until that whole response has come back.
  2. The workaround was more connections. Browsers open up to six per host, and sites spread assets over extra hostnames to get more. Every connection pays for its own TCP and TLS handshakes and starts with a small congestion window.
  3. HTTP/2 cuts each request and response into frames tagged with a stream number and interleaves them on a single connection. All three requests leave at once, and their repeated headers are compressed.
  4. The three responses come back interleaved in the same way. One handshake, one congestion window, and no queue in the browser.
  5. Now a single TCP packet is lost, and it carried part of the stylesheet. TCP must deliver bytes in order, so it holds back everything behind the gap, including frames for the script and the image that have already arrived.
  6. Every stream waits for one retransmission. This is TCP head-of-line blocking. On a lossy mobile network, six HTTP/1.1 connections can beat one HTTP/2 connection, because a loss stalls only one of the six.
  7. HTTP/3 replaces TCP with QUIC, which runs over UDP and understands streams. Each stream is ordered on its own, so the transport no longer forces unrelated responses into one line.
  8. The same packet is lost. Only the stylesheet's stream waits for the retransmission. The script and the image are delivered as soon as their own packets arrive.
  9. Each version removed one queue. HTTP/1.1 queued requests in the browser. HTTP/2 moved the queue down into TCP. HTTP/3 took ordering out of the transport, so a lost packet delays only the stream it belonged to.
Three requests on HTTP/1.1, HTTP/2 and HTTP/3

HTTP/1.1: keep-alive, pipelining and six connections

HTTP/1.1 made connections persistent by default. After a response, the connection stays open for the next request, which saves the handshakes and keeps the congestion window warm. This is what people mean by keep-alive.

The limit remained that a connection handles one exchange at a time. The standard’s answer was pipelining: send several requests back to back without waiting. It failed in practice, for two reasons. Responses still had to come back in the order requested, so one slow response held up everything behind it. And enough proxies and servers handled pipelined requests incorrectly that browsers could not safely turn it on.

Browsers settled on parallel connections instead, up to six per host. That gives six-way parallelism at six times the handshakes, six cold congestion windows and six times the connection state on the server.

HTTP/2: many streams, one connection

HTTP/2 was standardised in 2015 and grew out of Google’s SPDY experiment. It keeps HTTP’s methods, headers and status codes, and changes how they travel.

  • Binary framing and multiplexing. Each request and response is a stream, cut into frames that carry a stream number. Frames from many streams are interleaved on one TCP connection and reassembled at the other end. A slow response no longer blocks the others, and one connection is enough.
  • Header compression (HPACK). HTTP/1.1 sends every header in full with every request, often several hundred bytes of cookies and user-agent strings. HPACK keeps a table of headers already sent on the connection and refers to them by index.
  • Server push. The server could send resources before the browser asked. It proved hard to use well, and Chrome removed support in 2022. Do not offer it as a selling point.

Browsers only use HTTP/2 over TLS, negotiated during the TLS handshake. With HTTP/2, domain sharding becomes harmful, because it splits traffic over connections that could have been one.

Two problems remain. The first is TCP head-of-line blocking. HTTP/2 removed the queue at the HTTP layer, but all streams still share one ordered byte stream. When a packet is lost, TCP holds back everything after it, whichever stream it belongs to. On a clean network this is rare. On a lossy mobile network it can make one HTTP/2 connection slower than six HTTP/1.1 connections.

The second matters inside your own system. An HTTP/2 connection is long-lived and carries many requests. An L4 load balancer chooses a backend once per connection, so every request on that connection reaches the same server. For HTTP/2 and gRPC you need an L7 load balancer that balances individual requests, or clients that spread requests over several connections.

HTTP/3: HTTP over QUIC

HTTP/3, standardised in 2022, moves HTTP off TCP. It runs on QUIC, a transport protocol built on UDP that provides what TCP did (reliability, congestion control) with a different structure.

  • Streams live in the transport. QUIC orders data within each stream but not across streams. A lost packet delays only the streams whose data it carried.
  • One combined handshake. QUIC includes TLS 1.3, and sets up transport and encryption together.
  • 0-RTT resumption. A client that has spoken to the server before can send a request in its very first packet.
  • Connection migration. A connection is named by a connection ID, not by the pair of IP addresses and ports. When a phone leaves Wi-Fi for mobile data, the connection carries on.
New connection using Round trips before the request is sent
TCP + TLS 1.2 3
TCP + TLS 1.3 2
QUIC (HTTP/3) 1
QUIC, resumed with 0-RTT 0

A browser cannot know in advance that a server speaks HTTP/3. It usually connects over TCP first and learns from an Alt-Svc response header, or from an HTTPS record in DNS, that HTTP/3 is available. If UDP is blocked, it stays on HTTP/2.

HTTP/3 has costs. QUIC runs in user space and encrypts nearly everything, so it uses more CPU per byte than TCP, which has decades of kernel and hardware optimisation behind it. Some corporate networks block UDP. Load balancers must route by connection ID, or migration breaks. And packet captures show much less, which makes debugging harder.

Which to use where

Hop Usual choice Why
Browser or app to CDN or edge HTTP/3, falling back to HTTP/2 Lossy, high-latency networks are where QUIC helps most
Edge to origin HTTP/2 or pooled HTTP/1.1 Few, warm, long-lived connections on good links
Service to service HTTP/2 (often gRPC) or pooled HTTP/1.1 Loss is rare in a data centre, and tooling is mature

Choose HTTP/3 where the network is bad and connections are new: phones, long distances, first visits. In practice you get it by switching it on at the CDN or cloud load balancer, with the fallbacks handled for you. Do not push for it between your own services. The loss that makes TCP head-of-line blocking painful is rare there, and you would pay the CPU and tooling cost for little gain. HTTP/1.1 remains fine for simple internal calls, as long as you pool connections.

In the interview

This comes up as a direct question (“what changed between the versions?”), inside “what happens when you type a URL”, and whenever you draw a client on a mobile network.

A strong answer follows the queue. HTTP/1.1 allows one request per connection, so browsers open six. HTTP/2 multiplexes streams over one connection and compresses headers, but a lost TCP packet stalls all streams. HTTP/3 uses QUIC over UDP, so loss affects one stream, the handshake takes one round trip, and connections survive a network change. Then place them: HTTP/3 with fallback at the edge, HTTP/2 or gRPC inside, and an L7 balancer wherever HTTP/2 connections are long-lived.

Key takeaways

  • HTTP/1.1 reuses connections but carries one request at a time on each, so browsers open up to six connections per host.
  • HTTP/2 multiplexes many streams over one TCP connection and compresses headers, which removes the application-level queue.
  • HTTP/2 still sits on TCP, so one lost packet stalls every stream. HTTP/3 fixes that by moving to QUIC over UDP.
  • QUIC combines the transport and TLS 1.3 handshakes into one round trip, offers 0-RTT resumption, and survives a change of network.
  • 0-RTT data can be replayed by an attacker, so only allow it for idempotent requests.
  • Use HTTP/3 with HTTP/2 fallback between users and the edge. Inside the data centre, HTTP/2 or pooled HTTP/1.1 is the normal choice.

Check yourself

1. HTTP/1.1 pipelining let a client send several requests without waiting for responses. Why did browsers never rely on it?
2. On a mobile network with noticeable packet loss, a site performs worse on HTTP/2 than it did on HTTP/1.1. What is the most likely reason?
3. Three gRPC backends sit behind an L4 load balancer. One client service sends thousands of requests per second and nearly all of them land on one backend. Why?
4. Your CDN offers 0-RTT for HTTP/3. Which request is safe to accept as early data?
5. A user is 150 ms round trip from your edge and has never connected before. How long is connection setup before the first request can be sent, on HTTP/2 with TLS 1.3 and on HTTP/3?

0 of 5 answered

Flashcards

These 6 cards are in your review deck. Tap a card to see the answer.

Why do browsers open up to six HTTP/1.1 connections per host?

An HTTP/1.1 connection carries one request at a time, so parallel downloads need parallel connections. Six is the limit browsers settled on.

What are the two main things HTTP/2 added?

Multiplexing, where many request and response streams are interleaved as frames on one connection, and HPACK header compression, which stops repeated headers such as cookies being sent in full each time.

Where is head-of-line blocking in HTTP/1.1, HTTP/2 and HTTP/3?

HTTP/1.1: in the application, one request per connection. HTTP/2: in TCP, where one lost packet stalls every stream. HTTP/3: only within a single stream, because QUIC orders streams independently.

What is QUIC?

A transport protocol that runs over UDP, with built-in TLS 1.3, independent streams, its own congestion control and connection IDs. HTTP/3 is HTTP carried over QUIC.

What is connection migration?

A QUIC connection is identified by a connection ID, not by IP addresses and ports, so it survives when a phone moves from Wi-Fi to mobile data. A TCP connection would break and need new handshakes.

Why is 0-RTT risky?

The early data is sent before the handshake completes, so an attacker who records it can replay it and the server may process it twice. Restrict it to idempotent requests.

Review the deck