Skip to content
Tutorials Center
My learning

Topics

Lesson 49 of 79 ยท Application Layer: Names and Web

HTTP/1.1, HTTP/2 and HTTP/3

See how HTTP grew from one request per connection to multiplexed HTTP/2 and QUIC-based HTTP/3, and why head-of-line blocking drove each change. Live Node demos.

In HTTP Fundamentals you saw that a request and a response are just structured text sent over a connection. The meaning of HTTP (methods, status codes, headers) has hardly changed in decades. What changed is how those messages are carried over the network, because a modern page needs dozens or hundreds of resources and the original design handled that badly.

This lesson follows the three major versions that are in use today. Each one exists to remove a specific bottleneck of the previous one, and the bottleneck is always the same idea: head-of-line blocking, where one slow item holds up everything queued behind it. If you understand where the queue is in each version, you understand why the versions differ.

HTTP/1.0 and HTTP/1.1: one request at a time

HTTP/1.0 opened a new TCP connection for every request and closed it after the response. That is expensive: each connection costs a handshake round trip (and, with HTTPS, more round trips for TLS), and a fresh connection starts with a tiny congestion window, so it transfers slowly at first.

HTTP/1.1 (1997, refined in RFC 9112) fixed the worst of this:

  • Persistent connections. The connection stays open after a response and is reused for the next request. Connection: close is how either side says "this is the last one". Reuse removes repeated handshakes and keeps the congestion window warm.
  • The Host header became mandatory, so one IP address can serve many sites (virtual hosting).
  • Chunked transfer encoding lets a server start sending a response before it knows the total length.
  • Better caching controls, which the next lesson covers.

Run the experiment below. The server counts how many TCP connections it accepts. The client makes five sequential requests, first with keep-alive off and then on.

Node.js Connection reuse: close versus keep-alive

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Five connections versus one. On a real network every extra connection also costs at least one round trip, so the saving is roughly four round trips here.

Pipelining and why it failed

Persistent connections still have a rule: on one connection the client sends a request, waits for the complete response, and only then sends the next. A big or slow response blocks everything behind it. HTTP/1.1 defined pipelining, where the client sends several requests without waiting, but the server must still reply in order. If the first response is slow, the others wait even if they are ready. That is head-of-line blocking at the HTTP level. Broken proxies and servers made pipelining unreliable, and browsers turned it off.

The practical workaround was brute force: browsers open about six parallel connections per host. Sites went further with domain sharding (spreading assets over img1.example, img2.example...) and bundling many files into one. These hacks cost memory, extra handshakes, and a congestion window that never grows on any one connection. They also compete unfairly with other users' traffic.

HTTP/2: many streams on one connection

HTTP/2 (RFC 9113) keeps the HTTP semantics but changes the wire format from text to binary frames, and it lets a single TCP connection carry many conversations at once.

flowchart LR
    subgraph C["One TCP connection"]
      S1["Stream 1: /index.html"]
      S3["Stream 3: /app.css"]
      S5["Stream 5: /logo.svg"]
    end
    S1 --> F["Frames from different<br/>streams are interleaved"]
    S3 --> F
    S5 --> F
    F --> W["Single byte stream<br/>over TCP"]

Each request is a numbered stream. Its messages are cut into frames, and frames from many streams are mixed on the wire.

The key ideas:

  • Frames and streams. A message is split into frames (HEADERS, DATA and a few control types), each tagged with a stream number. The receiver sorts frames back into their streams. Client-initiated streams use odd numbers.
  • Multiplexing. A slow response no longer blocks others, because their frames can be sent in between. One connection is enough, so there is no need for six connections or sharding.
  • Stream priorities and flow control. Each stream has its own flow-control window, on top of TCP's, so a slow consumer of one stream cannot swamp the whole connection.
  • HPACK header compression. Headers such as user-agent and cookie are repeated on every request and can add up to kilobytes. HPACK keeps a table of recently seen header lines at both ends, and later requests send just a small index number. It deliberately avoids general-purpose compression like gzip because compressing secrets together with attacker-controlled data leaked cookies (the CRIME attack).
  • Server push let a server send a resource it expected the client to need, before the client asked. In practice it was hard to use well, often wasted bandwidth by sending things already cached, and Chrome removed support in 2022. Use 103 Early Hints or <link rel="preload"> instead.

Browsers speak HTTP/2 only over TLS, and they learn that the server supports it during the TLS handshake through the ALPN extension (a list of protocol names such as h2 and http/1.1).

The next demo is a model, not a real network: it uses virtual time to show how the request pattern changes the total load time. Each request needs one round trip (40 ms) before data starts arriving, and the shared link can carry one 10 ms resource at a time.

Node.js Loading 12 resources: connections versus multiplexing

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

HTTP/2 with one connection matches what many connections can do, without their overhead. Next, a toy version of the HPACK idea. It is not the real HPACK encoding (which uses a static table, Huffman coding and variable-length integers), but it shows why repeated headers become cheap.

Node.js A toy header-compression table

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The remaining problem: TCP itself

HTTP/2 removed head-of-line blocking between requests, but TCP delivers one ordered byte stream. If one packet is lost, TCP holds back every byte after it until the retransmission arrives (see TCP reliability), even bytes that belong to completely different HTTP/2 streams. On a lossy mobile network, one connection can be worse than six, because a single loss stalls all streams.

HTTP/3: HTTP over QUIC

HTTP/3 (RFC 9114) keeps the HTTP/2 ideas (streams, header compression, now called QPACK) but replaces TCP with QUIC, a transport built on UDP. We cover QUIC in detail in QUIC, SCTP and modern transports; the headlines for HTTP are:

flowchart TB
    subgraph H2["HTTP/2 stack"]
      A1["HTTP/2"] --> A2["TLS 1.2 / 1.3"] --> A3["TCP"] --> A4["IP"]
    end
    subgraph H3["HTTP/3 stack"]
      B1["HTTP/3"] --> B2["QUIC<br/>(streams, loss recovery, TLS 1.3)"] --> B3["UDP"] --> B4["IP"]
    end

QUIC folds the transport and the TLS handshake into one layer on top of UDP.

  • Independent streams. QUIC knows about streams itself. A lost packet only delays the streams whose data was in it; the others keep flowing.
  • Faster setup. QUIC combines the transport and TLS 1.3 handshakes, so a new connection needs one round trip, and a returning client can often send data in the first flight (0-RTT).
  • Always encrypted. TLS 1.3 is built in, and most of the QUIC header is encrypted too, which stops middleboxes from interfering with it.
  • Connection migration. A connection is identified by a connection ID, not by the IP address and port pair. A phone that moves from Wi-Fi to cellular can keep the same connection.
  • Runs in user space. Because it is on UDP, QUIC is implemented in applications and libraries, so it can evolve without waiting for operating-system updates.

How does a browser know a site offers HTTP/3? The server announces it with an Alt-Svc: h3=":443" response header (or in a DNS HTTPS record). The first visit typically uses HTTP/2 over TCP, and the browser switches to HTTP/3 if it works, falling back if UDP is blocked.

HTTP/1.1 HTTP/2 HTTP/3
Wire format Text Binary frames Binary frames
Transport TCP TCP QUIC over UDP
Requests per connection One at a time Many multiplexed Many multiplexed
Header compression None HPACK QPACK
HOL blocking At HTTP level At TCP level Per stream only
Encryption Optional Practically always Always

You rarely write code for a specific version. Your server and the browser negotiate the best one, and your application sees the same requests and responses. Your choices are deployment ones: enable HTTP/2 and HTTP/3 on the web server or CDN, and make sure UDP port 443 is open for HTTP/3.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the main benefit of HTTP/1.1 persistent connections over HTTP/1.0?

    Persistent connections let later requests reuse an open TCP connection, which saves handshake round trips and keeps the congestion window warm. Parallelism on one connection arrived with HTTP/2.
  2. 2. Why did browsers open about six connections per host with HTTP/1.1?

    With one request at a time per connection, parallelism needs several connections. HTTP/2 multiplexing makes this workaround unnecessary.
  3. 3. What problem of HTTP/2 does HTTP/3 solve?

    All HTTP/2 streams share one TCP byte stream, so one lost packet delays every stream. QUIC delivers streams independently.
  4. 4. How does a client learn it can use HTTP/2 during an HTTPS handshake?

    ALPN (Application-Layer Protocol Negotiation) lets client and server agree on h2 or http/1.1 inside the TLS handshake, with no extra round trip.
  5. 5. Why does HPACK not simply use gzip for headers?

    Generic compression of headers made it possible to guess cookie values from compressed sizes. HPACK uses a table design that avoids this.

Summary

  • HTTP's semantics stayed stable; the versions differ in how messages are carried.
  • HTTP/1.1 added persistent connections but handles one request at a time per connection, so browsers open several connections to compensate.
  • HTTP/2 uses binary frames, multiplexed streams on one connection and HPACK header compression. Server push is effectively dead.
  • TCP's ordered byte stream still lets one lost packet stall all HTTP/2 streams.
  • HTTP/3 runs over QUIC (UDP): independent streams, faster setup with built-in TLS 1.3, connection migration, announced through Alt-Svc.
  • Your application code stays the same; enabling the newer versions is a server or CDN setting.

Next, learn how HTTP avoids repeating work at all in Caching, Cookies and State.