Skip to content

HTTP/1.1, HTTP/2 and HTTP/3

A request is a method, a path and some header fields. A response is a status, header fields and a body. These meanings are the same in every version of HTTP. What changed between versions is how the messages travel: how many connections, how many requests at a time on each, and over which transport. Those choices decide how long a page with many resources takes to load.

Mental model. HTTP/1.1 is a queue at each counter, with several counters. HTTP/2 is one counter that serves everyone’s requests in turn, interleaved. HTTP/3 is the same idea with a counter that does not stop for everybody when one parcel is lost.

HTTP/1.1: one at a time, several connections

Section titled “HTTP/1.1: one at a time, several connections”

HTTP/1.1 connections are persistent by default, as RFC 9112 says, so a connection can carry many requests, one after the other. A client may send several requests without waiting, which is called pipelining, but the server must return the responses in the order the requests arrived, so a slow response holds up the ones behind it. That, and buggy intermediaries, are why pipelining is not turned on by default in modern browsers.

The workaround is more connections. According to MDN, browsers open several connections to each domain and send parallel requests, commonly up to six. Each connection pays for its own TCP and TLS handshakes, uses memory on the server, and has to find its own pace on the network.

HTTP/2 interleaves messages on a single connection, as separate streams, so the client can have many requests in flight at once on one TCP connection and one handshake. It also compresses header fields, because they are repetitive and verbose. A browser does not need six connections any more.

But it multiplexes above TCP, and TCP sees one ordered byte stream. RFC 9113 says plainly that TCP head-of-line blocking is not addressed by the protocol. If one packet is lost, TCP holds back all the bytes behind it until the missing one is resent, and every stream on the connection waits, including the ones whose data had already arrived.

HTTP/3 maps HTTP onto QUIC, which runs over UDP. Streams are independent of each other: RFC 9114 says that a stream that is blocked or suffers packet loss does not prevent progress on the others, because QUIC provides reliability stream by stream. And the handshake is one round trip, since the transport and TLS 1.3 are negotiated together, as the last lesson showed.

Eight statements about how the versions behave. Which version does each one describe?

Challenge

Which HTTP version?

HTTP/1.1, HTTP/2 and HTTP/3 carry the same requests and responses in different ways. Put each statement under the version it describes.

Sorting needs JavaScript.

Categories

HTTP/1.1
One request at a time on a connection, in order.
HTTP/2
Many streams on one TCP connection.
HTTP/3
Many streams over QUIC.
  1. Line 1 of 8Responses come back in the order the requests were sent on a connection, so a slow response holds up the ones behind it.
  2. Line 2 of 8To load many resources at once, a browser opens several connections to the same server, commonly around six.
  3. Line 3 of 8Header fields are sent as plain text, in full, with every request.
  4. Line 4 of 8Many requests share one TCP connection, interleaved as separate streams, so a browser no longer needs six connections.
  5. Line 5 of 8One lost packet stalls every stream on the connection, because TCP delivers bytes in order.
  6. Line 6 of 8It runs over QUIC, on UDP, with TLS 1.3 built into the handshake.
  7. Line 7 of 8A lost packet stalls only the streams whose data it carried. The others carry on.
  8. Line 8 of 8A new connection needs one round trip before the request can be sent, because transport and encryption are set up together.

Check your answers at least once before looking at the answers.

Take a page that needs 30 small resources, at a round-trip time of 80 ms and a server that takes 20 ms for each. To keep the comparison to what the versions do with connections, assume that all 30 resources are known at the start, that they are small enough for bandwidth not to matter, and that the server can work on all of them at once.

  • HTTP/1.1 over TCP and TLS 1.3, with six connections. Each connection opens at the same time, and the first request on it is answered after 260 ms: 2 round trips for the handshakes, 1 for the request, and 20 ms. Each connection has five requests to make, one after the other, and each of the four that follow costs a round trip and the server’s time, 80 + 20 = 100 ms. The last response arrives after 260 + 4 × 100 = 660 ms.
  • HTTP/2 over TCP and TLS 1.3, with one connection. All 30 requests leave together, as 30 streams, and the answers come back in the same round trip: 260 ms.
  • HTTP/3 over QUIC. The same 30 streams, after one round trip for the handshake instead of two: 180 ms.

The ratio is what matters. At 300 ms instead of 80 ms, the same arithmetic gives 2,200 ms for HTTP/1.1, 920 ms for HTTP/2 and 620 ms for HTTP/3. Parallelism that costs a round trip per wave, and handshakes that cost round trips per connection, are expensive in proportion to the distance.

What happens if the network loses packets?

Section titled “What happens if the network loses packets?”

On a connection that is losing a small share of its packets, HTTP/2 and HTTP/3 behave differently. In HTTP/2, one lost segment holds back every stream until it has been resent, which takes at least a round trip: 80 ms here, during which none of the 30 responses progresses. In HTTP/3, only the streams whose data was in the lost packet wait. The other streams carry on, and a loss that affects one image does not stop the script that is next to it.

Avoiding this stall is one of the reasons that HTTP/3 was built on QUIC and not on TCP. Where a network rarely loses packets there is little stalling to avoid, and the gain of HTTP/3 comes mostly from its shorter handshake, which counts for most over long distances.

  • The meaning of requests and responses is the same in every version. What changes is how they travel.
  • HTTP/1.1 sends one request at a time on a connection and answers in order, so browsers open several connections, commonly up to six, each paying its own handshakes.
  • HTTP/2 puts many streams on one TCP connection and compresses headers. A single lost packet stalls every stream, because TCP delivers bytes in order.
  • HTTP/3 runs over QUIC, with independent streams and a one-round-trip handshake. A lost packet stalls only the streams it carried.
  • For 30 small resources at 80 ms and 20 ms of server time, the example gives 660 ms for HTTP/1.1 with six connections, 260 ms for HTTP/2 and 180 ms for HTTP/3. At 300 ms, 2,200, 920 and 620 ms.
  • HTTP/3 gains from a shorter handshake, which counts most over long distances, and from not stalling every stream on a loss.

Next: connection pooling and keep-alive, and what it saves to open a connection once.

Your progress

Built by GhaziAlibi.

© ShardCraft. All rights reserved.