HTTP/2: frames, streams and head-of-line blocking
HTTP/2 sends many requests over one connection as interleaved binary frames. Learn the framing, HPACK compression and flow control, and the TCP-level blocking HTTP/2 could not fix.
HTTP/1.1 sends one request at a time per connection. A slow response blocks everything behind it on that connection: application-level head-of-line blocking. Browsers opened six connections per origin, and sites sharded assets across domains, just to get parallelism.
HTTP/2 keeps HTTP's semantics but replaces the text format with binary frames. Every request and response becomes a stream with an ID, and frames from many streams interleave on one connection. A slow response no longer blocks others at the HTTP level.
| Frame | Purpose |
|---|---|
| HEADERS | Starts a stream; carries compressed headers |
| DATA | Body bytes for one stream |
| SETTINGS | Connection parameters, such as max concurrent streams |
| WINDOW_UPDATE | Flow control: permission to send more |
| RST_STREAM | Cancel one stream without closing the connection |
| GOAWAY | Graceful shutdown: no new streams after this ID |
| PING | Liveness and RTT measurement |
Each frame has a 9-byte header: 24-bit length, 8-bit type, 8-bit flags, and a 31-bit stream ID. Client-initiated streams use odd IDs. Because frames are length-prefixed, the receiver always knows where each one ends, the framing lesson from Module 4 applied.
HPACK header compression
Request headers repeat almost entirely between requests: the same host, user agent, cookies and accept headers. HPACK compresses them with three tools: a static table of 61 common header fields, a dynamic table of headers this connection has already sent, and Huffman coding for literal strings. A repeated header shrinks to a single byte index.
- First request sends
authorization: Bearer eyJ…(about 900 bytes), and adds it to the dynamic table at index 62- Second request sends
- One byte: “indexed header field 62”
- Saved per request
- ~899 bytes
Over 1,000 requests on one connection, nearly 1 MB of header bytes is never sent.
The block HTTP/2 could not remove
One lost packet, three streams
- Stream A complete at
- slot 4
- Stream B complete at
- slot 13
- Stream C complete at
- slot 13
Streams interleave, but TCP delivers bytes in order: every packet after B2, from any stream, waits for the retransmission. C finishes late though none of its packets were lost.
Streams are independent to HTTP/2, but TCP sees one byte stream. When a packet is lost, TCP holds back every later byte, whichever stream it belongs to, until the retransmission arrives. On a clean data-centre network that is rare and cheap. On a mobile link with 2% loss, a single HTTP/2 connection can perform worse than six HTTP/1.1 connections.
Flow control
HTTP/2 adds its own flow control on top of TCP's, per stream and per connection. A receiver grants credit with WINDOW_UPDATE frames. This lets one slow consumer, such as a stalled download, stop without starving every other stream on the connection.
Go deeperRapid Reset: a protocol feature as an attack
In October 2023, attackers exploited a simple pattern: open a stream with HEADERS, immediately cancel it with RST_STREAM, repeat. The client stays within its concurrent-stream limit because each stream is closed at once, but the server has already started work for every request. Record-breaking request floods followed (CVE-2023-44487).
Servers now count resets and close connections that cancel too many streams. The lesson generalises: any cheap-for-client, expensive-for-server operation in a protocol needs a budget. Agent tool servers face the same shape when a client can start and cancel expensive tool runs freely.
Where you will meet it
gRPC maps each call to an HTTP/2 stream, uses trailers for status, and cancels calls with RST_STREAM.
HTTP/2 server push was removed from major browsers because it rarely helped. 103 Early Hints replaced it: the server suggests what to preload.
Under HTTP/2, splitting assets across domains hurts, because each domain needs its own connection and handshake.
Words to know
- Stream
- One request-response exchange inside an HTTP/2 or HTTP/3 connection.
- Frame
- HTTP/2's unit on the wire: 9-byte header plus payload.
- HPACK
- HTTP/2 header compression with static and dynamic tables.
- Head-of-line blocking
- A stalled item at the front of a queue delaying everything behind it.
Check yourself
Answer out loud before you open each one.
Head-of-line blocking exists at which layers?
HTTP/1.1 at the application layer, TCP at the transport layer under HTTP/2, and QPACK dynamic-table references under HTTP/3.
What does HPACK's dynamic table store?
Header fields already sent on this connection, so repeats can be sent as small indexes.
Why can HTTP/2 be slower than HTTP/1.1 on a lossy link?
One lost packet blocks every stream on the single TCP connection, while six HTTP/1.1 connections lose independently.
Try it
Run curl -sv --http2 https://example.com -o /dev/null 2>&1 | grep -i 'alpn\|http/2'. Then use nghttp -nv https://example.com if you have it, to see individual frames.