Course contents

02. Networking and Internet Lesson 7 of 10

HTTP/2 and HTTP/3

Compare HTTP/1.1 connections, HTTP/2 multiplexing and HTTP/3 over QUIC: see TCP head-of-line blocking on loss, one-round-trip setup and connection migration.

14 minIntermediate9 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • HTTP/1.1 handles one request at a time per connection; browsers open up to six connections per host to compensate.
  • HTTP/2 multiplexes many streams on one TCP connection with compressed headers.
  • On packet loss, TCP’s in-order delivery stalls every HTTP/2 stream until the retransmission arrives.
  • HTTP/3 runs on QUIC over UDP: TLS 1.3 is built in, setup takes one round trip and loss only delays its own stream.
  • QUIC connections survive address changes via connection IDs; HTTP/3 is discovered via Alt-Svc or HTTPS records and always backed by TCP.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

HTTP/2 (RFC 9113) and HTTP/3 (RFC 9114) keep HTTP’s semantics — methods, status codes, headers — and change how messages travel. HTTP/2 multiplexes many request/response streams over one TCP connection using binary frames. HTTP/3 does the same over QUIC (RFC 9000), a transport built on UDP that provides reliability, congestion control and streams itself and integrates TLS 1.3.

Why it exists

HTTP/1.1 sends one request at a time per connection and the response must come back before the next request (pipelining exists but was never usable in browsers). Pages load dozens of resources, so browsers opened up to six connections per host and sites added hostnames (domain sharding) to get more. Every connection pays its own TCP and TLS handshakes, starts with a small congestion window and competes with its siblings. HTTP/2 removed the need for multiple connections; HTTP/3 then removed the remaining transport-level problems that TCP imposes.

How it works

HTTP/2. Each request and response is split into HEADERS and DATA frames carrying a stream ID (client streams are odd: 1, 3, 5…). Frames from different streams interleave on one connection, so a slow response does not block others at the HTTP layer. HPACK compresses headers with static and dynamic tables, so repeated cookies and user agents cost a few bytes. Flow control works per stream and per connection; the server limits concurrency with SETTINGS_MAX_CONCURRENT_STREAMS (commonly 100 or more). Server push was specified but browsers removed support; 103 Early Hints is the replacement.

TCP head-of-line blocking. TCP delivers an ordered byte stream. If one segment is lost, everything after it waits in the receive buffer until the retransmission arrives — even frames belonging to other streams that are complete. On a clean network this is rare; on lossy Wi-Fi or mobile links one loss stalls every stream on the connection for at least a round trip.

QUIC and HTTP/3. QUIC runs in user space over UDP. Streams are a transport concept: each has its own ordering, so a loss delays only the stream whose data was lost. The QUIC handshake carries TLS 1.3, so a new connection is ready after one round trip (TCP + TLS 1.3 need two); resumed connections can send 0-RTT data. Packet headers are mostly encrypted, which stops middleboxes from depending on (and ossifying) transport details. HTTP/3 uses QPACK instead of HPACK, designed so header compression does not reintroduce cross-stream blocking.

Connection migration. A TCP connection is identified by source/destination address and port. When a phone changes networks, its address changes and the connection is dead. QUIC identifies connections by connection IDs; a client can continue from a new address after the server validates the path (PATH_CHALLENGE/PATH_RESPONSE). Load balancers in front of QUIC servers must route by connection ID (e.g. encoding a server ID in it) for this to work.

Discovery and fallback. A client does not know in advance that a server speaks HTTP/3. Servers advertise it with the Alt-Svc: h3=":443" response header or a DNS HTTPS record (RFC 9460) carrying alpn=h3. Browsers race QUIC against TCP and fall back to HTTP/2 when UDP is blocked or slow.

When to use it

  • Serve HTTP/2 everywhere TLS is used; it is the baseline for browsers and gRPC.
  • Add HTTP/3 at the edge (CDN, load balancer) for user-facing traffic, especially mobile and lossy networks, and for clients that move between networks.
  • gRPC is built on HTTP/2 streams; long-lived streaming APIs benefit from multiplexing.

When not to

  • HTTP/3 inside a data centre rarely pays off: loss is low, connections are long-lived, and kernel TCP with offloads is cheaper per byte than user-space QUIC.
  • HTTP/1.1 remains fine for simple internal calls, health checks and tooling; many proxies still speak HTTP/1.1 to origins.
  • Do not rely on HTTP/3 alone: some networks block UDP.

Trade-offs

Choice You gain You pay
HTTP/2 instead of many HTTP/1.1 connections One handshake, shared congestion control, header compression Transport head-of-line blocking on loss; one connection carries everything
HTTP/3 instead of HTTP/2 One-round-trip setup, per-stream loss recovery, migration More CPU per byte, UDP may be blocked, newer tooling, QUIC-aware load balancing
0-RTT on QUIC First request in the first flight Replay risk for non-idempotent requests

Alternatives

  • HTTP/1.1 with keep-alive for simple clients and internal hops.
  • WebSockets (over HTTP/1.1, or HTTP/2 and HTTP/3 via extended CONNECT) for bidirectional messaging; Server-Sent Events for one-way streams (see those lessons).
  • WebTransport over HTTP/3 for low-latency bidirectional streams and unreliable datagrams in browsers.

Failure modes

  • Lossy links with HTTP/2: one connection means one loss stalls all streams; at high loss rates multiple HTTP/1.1 connections can even outperform a single HTTP/2 connection.
  • Concurrency limits: a low MAX_CONCURRENT_STREAMS or connection-level flow-control window throttles throughput silently.
  • Abuse of multiplexing: rapid stream creation and cancellation (the 2023 “Rapid Reset” attack) can overload servers; keep proxies patched and limit stream churn.
  • UDP blocked or rate-limited: HTTP/3 attempts stall until fallback kicks in.
  • Load balancers unaware of QUIC: migrated or 0-RTT packets reach the wrong backend.

In production

Terminate HTTP/2 and HTTP/3 at the CDN or load balancer; most managed edges support both. Advertise HTTP/3 with Alt-Svc and HTTPS DNS records. Keep TCP available. Use HTTP/2 or HTTP/1.1 with keep-alive and connection pools to the origin. Drop HTTP/1.1 hacks (domain sharding, spriting, inlining everything) that hurt under multiplexing. Monitor protocol mix, handshake times and retransmission rates per network type.

Common misconceptions

  • “HTTP/2 fixed head-of-line blocking.” At the HTTP layer, yes; at the TCP layer, no.
  • “QUIC is unreliable because it uses UDP.” QUIC implements reliable, ordered streams itself; UDP only carries its packets.
  • “HTTP/3 makes every request faster.” It mainly helps setup latency and lossy or changing networks; on clean, warm connections the difference is small.
  • “Server push is how HTTP/2 speeds up pages.” Browsers removed push; 103 Early Hints and preload replaced it.

Interview angle

When designing a user-facing API or site, say which protocol you serve at the edge (HTTP/2 + HTTP/3 with TCP fallback) and what you use to the origin. Explain head-of-line blocking at both layers in one sentence each, count round trips for new connections (two for TCP + TLS 1.3, one for QUIC), and mention connection migration for mobile clients. For real-time features, connect this to WebSockets, SSE or WebTransport.

Model assumptions

This lesson is a scripted walk-through, not a simulation: the engine has no TCP, QUIC or packet-loss model, so every packet is placed by hand to show order and timing. One-way latency is 10 ms from the phone to the Wi-Fi or cellular network and 10 ms on to the server (40 ms round trip); handing data from the phone’s transport stack to the page is drawn as a 2 ms hop. Each response is two frames per stream. Loss recovery is drawn as fast retransmission after three later packets are acknowledged; real stacks also use timers, and real congestion windows, packet sizes and server processing are not modelled. Numbers are illustrative.

The lesson as textEvery step of the simulation, written out.
  1. 1. HTTP/1.1: one request at a time per connection

    *Scripted illustration.* The page needs three files: app.css, app.js and logo.png. Over an open HTTP/1.1 connection the browser sends one request and must wait for its whole response before the next can go: three round trips, about 125 ms here.

    HTTP/1.1 allows pipelining (several requests in a row), but responses must still come back in order and broken proxies made it unreliable, so browsers never enabled it.

    Scene: The phone sends three requests to the server one after another over a single connection, each waiting for the previous response. The page gets the third file after about 125 ms.

    Key idea: HTTP/1.1 serialises requests on a connection: one round trip per request.

  2. 2. The workaround: more connections

    *Scripted.* Browsers open up to six connections per host to get parallelism. Here three new connections fetch one file each. But every connection pays its own TCP and TLS handshakes (two round trips) before its request, starts with a small congestion window, and competes with the others for the same link.

    The three files arrive together after about 125 ms: no faster than the sequential version in this case, at three times the handshakes. Sites even split assets across extra hostnames (domain sharding) to get more connections.

    Scene: Three connections open in parallel. Each does a TCP and a TLS handshake, then requests one file. All three files arrive after about 125 ms.

    Key idea: Parallel HTTP/1.1 connections buy concurrency at the price of extra handshakes and unfair, uncoordinated congestion control.

  3. 3. HTTP/2: many streams, one connection

    *Scripted.* HTTP/2 splits each request and response into frames tagged with a stream ID. All three requests go out at once on streams 1, 3 and 5; the server interleaves the response frames on the same connection. Headers are compressed with HPACK, so repeated cookies and user agents cost almost nothing.

    All three files reach the page about one round trip after the requests leave, roughly 50 ms instead of 125, over one connection with one handshake and one congestion window.

    Scene: Three requests leave together on one connection; the server sends interleaved response frames for streams 1, 3 and 5. All three files reach the page about 50 ms after the start.

    Key idea: Multiplexing removes waiting in line at the HTTP level: many requests share one connection concurrently.

  4. 4. One lost packet stalls every stream

    *Scripted.* Now the Wi-Fi drops one packet: the first frame of stream 1. The frames of streams 3 and 5 arrive fine. But TCP promises an in-order byte stream: it cannot hand anything after the gap to the browser until the gap is filled.

    The phone sends duplicate ACKs, the server retransmits after about one more round trip, and only then do all three streams reach the page, around 85 ms instead of 50. HTTP/2 removed head-of-line blocking at the HTTP layer, but on a lossy link TCP head-of-line blocking hits every stream on the connection at once.

    Scene: The first frame of stream 1 is lost at the Wi-Fi. Frames for streams 3 and 5 reach the phone, but none is handed to the page until the retransmitted frame arrives about one round trip later; then all three streams are delivered together.

    Key idea: Over TCP, multiplexed streams share one ordered byte stream: a single loss delays all of them.

  5. 5. HTTP/3 runs on QUIC

    *Scripted.* HTTP/3 maps HTTP onto QUIC, a transport that runs over UDP and implements reliability, congestion control and streams itself, with TLS 1.3 built in. The first packet carries the ClientHello; the server’s reply completes both the transport and the crypto handshake.

    So the requests leave after one round trip (40 ms), where TCP + TLS 1.3 needed two. With a resumed session QUIC can even send the first request in its first packet (0-RTT, with the same replay caveat as TLS).

    Scene: A QUIC handshake: the phone sends its ClientHello, the server answers with one flight, and after one round trip the three requests leave on QUIC streams. The files reach the page about 90 ms after the start.

    Key idea: QUIC merges the transport and TLS handshakes: one round trip to the first request.

  6. 6. Loss only stalls its own stream

    *Scripted.* The same packet is lost again. QUIC tracks ordering per stream, so the frames of streams 4 and 8 (QUIC numbers its client streams 0, 4, 8) are handed to the page as soon as they arrive, around 50 ms. Only stream 0 waits for the retransmission, about one round trip longer.

    HTTP/3’s header compression, QPACK, was designed so headers do not reintroduce cross-stream blocking. On lossy mobile and Wi-Fi links this is where HTTP/3 helps most.

    Scene: The first frame of stream 0 is lost. Streams 4 and 8 are delivered to the page as soon as their frames arrive; only stream 0 waits for the retransmission.

    Key idea: Independent streams in the transport: a loss delays only the stream it belongs to.

  7. 7. Walking out of Wi-Fi range

    *Scripted.* The user leaves the café: the phone switches to cellular and gets a new IP address. A TCP connection is identified by its 4-tuple (addresses and ports), so the next segment from the new address matches nothing and the server answers with a reset. The browser must open a new connection: TCP + TLS handshakes and a fresh slow start.

    QUIC identifies connections by a connection ID, not by addresses. The server sees the known ID from a new address, checks that the phone really owns that path (PATH_CHALLENGE / PATH_RESPONSE) and carries on, with no new handshake. This is connection migration.

    Scene: The Wi-Fi goes offline and the phone moves to cellular. First, a TCP segment from the new address is answered with a reset. Then, over QUIC, the server validates the new path with a challenge and response and the data continues without a new handshake.

    Key idea: QUIC connections survive address changes because they are identified by connection IDs.

  8. 8. How the browser finds out, and when it falls back

    *Scripted.* Back on Wi-Fi. A browser cannot assume a server speaks HTTP/3. The first visit goes over TCP (HTTP/2), and the response carries Alt-Svc: h3=":443"; the next connection tries QUIC. A DNS HTTPS record (RFC 9460) can announce alpn=h3 before the first connection.

    Some networks block or throttle UDP, so browsers race QUIC against TCP and fall back silently. HTTP/2 is therefore never retired: a server offers both. QUIC also costs more CPU per byte than kernel TCP with offloads, which matters for heavy servers.

    Scene: The phone fetches a page over HTTP/2 and the response advertises HTTP/3 with Alt-Svc. The next connection starts with a QUIC Initial packet.

    Key idea: HTTP/3 is advertised (Alt-Svc, HTTPS records) and always backed by a TCP fallback.

  9. 9. Which version fixes what

    HTTP/1.1: one request at a time per connection, parallelism by opening more connections. HTTP/2: many streams on one TCP connection, compressed headers, but a lost packet stalls every stream. HTTP/3: streams in the transport (QUIC over UDP), one-round-trip setup, per-stream loss recovery and connection migration, with a TCP fallback.

    For system design: serve HTTP/2 and HTTP/3 at the edge (CDN or load balancer), keep HTTP/1.1 or HTTP/2 to the origin where connections are long-lived and loss is rare, and stop using HTTP/1.1-era hacks like domain sharding and sprite sheets.

    Scene: The phone, Wi-Fi, cellular network and server, idle: a summary of HTTP/1.1, HTTP/2 and HTTP/3.

    Key idea: HTTP/2 fixes HTTP-level queueing; HTTP/3 also fixes transport-level queueing and setup cost.