Lesson 10 of 18
3. Client and Server

3.9 Why do keep-alive, HTTP/2 and HTTP/3 make things faster?

3 min read+10 XP

In the restaurant: Three upgrades. The waiter stays at your table instead of walking off after every single order (keep-alive). The waiter carries many orders on one tray at once (HTTP/2). And when one plate on the tray drops, the others still get served instead of everyone waiting while it's remade (HTTP/3).

In the system: Every new connection costs handshakes before the first byte:

round trips before the first byte: new TCP+TLS connection, new QUIC connection, reused connection.

Figure: with a 100 ms round trip, a brand-new HTTPS connection waits 300 ms; a reused one waits 100 ms.

  • Keep-alive (persistent connections): reuse one TCP connection for many requests. It's the default in HTTP/1.1. You pay the handshakes once, not per request.
  • HTTP/2: sends many requests at the same time over one connection (multiplexing) and compresses headers. HTTP/1.1 in practice has one request in flight per connection, so browsers opened several connections to work around it.
  • HTTP/3: runs over QUIC, which is built on UDP. QUIC combines the transport and TLS handshakes (fewer round trips), and a lost packet only delays its own stream, not every request on the connection. That's TCP's head-of-line blocking removed. It also survives a phone switching from Wi-Fi to mobile data better.

Design lesson: the fastest handshake is the one you don't do. Reuse connections between your services too (connection pools to the database, to Redis, to other services).

Memory code: "Keep the waiter, fill the tray, don't stop for one dropped plate." Keep-alive, HTTP/2 multiplexing, HTTP/3 over QUIC.