Sub topic 15
Persistent Connections, Pipelining, and Newer HTTP Versions
Assume you know TCP connection setup, round-trip time (RTT), HTTP request and response structure, and common status codes. This chapter explains how HTTP uses transport connections more efficiently and why HTTP/2 and HTTP/3 changed the design.
HTTP/1.0 and Persistent Connections
An HTTP client can send a request over a TCP connection. In early HTTP/1.0, the server commonly closed the connection after sending each response:
- Open a TCP connection.
- Send one HTTP request.
- Receive one HTTP response.
- Close the connection.
Opening a TCP connection costs at least one RTT for the handshake before application data can be exchanged. Repeating this for many objects creates extra delay.
HTTP/1.1 makes connections persistent by default. The client can send several requests over the same TCP connection. The connection remains open unless one side sends Connection: close or a timeout closes it.
from http.client import HTTPConnection
connection = HTTPConnection("example.com", 80, timeout=10)
try:
connection.request("GET", "/")
first = connection.getresponse()
print(first.status, first.reason)
first.read() # Consume the body before sending another request.
connection.request("GET", "/about")
second = connection.getresponse()
print(second.status, second.reason)
second.read()
finally:
connection.close()The client must consume each response body before safely reusing the connection. HTTP/1.1 responses contain a Content-Length, use chunked transfer encoding, or end when the connection closes so that the client can identify the body boundary.
Pipelining and Head-of-Line Blocking
HTTP/1.1 pipelining allows a client to send multiple requests without waiting for each response. The server must return responses in the same order as the requests.
This ordering creates head-of-line blocking. If the first response is slow, later responses cannot be delivered to the application even if they are already ready. In practice, browser support for pipelining was limited, and clients often opened several parallel persistent TCP connections instead.
| Version | Main transport | Request handling | Important limitation |
|---|---|---|---|
| HTTP/1.1 | TCP | Ordered messages on a connection | Head-of-line blocking |
| HTTP/2 | TCP | Multiplexed streams | TCP loss can block all streams |
| HTTP/3 | QUIC over UDP | Multiplexed independent streams | Requires QUIC support |
HTTP/2: Multiplexed Streams
HTTP/2 uses binary frames instead of HTTP/1.1 text lines. A single TCP connection carries multiple logical streams. Each stream represents a request and its response, so frames from different streams can be interleaved.
HTTP/2 also provides:
- Header compression using HPACK.
- One connection for many concurrent requests.
- Stream identifiers and stream-level control.
- Server push in the original design, although many deployments avoid it.
Multiplexing removes HTTP/1.1 response ordering between separate requests. However, TCP delivers one ordered byte stream. If a TCP segment is lost, TCP must recover it before delivering later bytes. Therefore, packet loss can still block every HTTP/2 stream on that connection.
HTTP/3: QUIC and UDP
HTTP/3 runs over QUIC, a transport protocol built above UDP. QUIC provides reliable delivery, congestion control, encryption, and multiple independent streams.
Loss on one QUIC stream does not require unrelated streams to wait. This reduces transport-level head-of-line blocking. QUIC also combines connection setup with TLS 1.3 and supports connection migration, which helps a connection survive a change from Wi-Fi to cellular data.
HTTP/3 does not mean that UDP is reliable by itself. QUIC adds the reliability and congestion-control mechanisms that applications need.
Exercise
A page needs ten small objects. Why can one persistent HTTP/1.1 connection be faster than ten separate connections, and why can HTTP/2 still suffer from packet loss?
Show answer
Reusing one connection avoids repeated TCP handshakes and slow-start periods. HTTP/2 multiplexes the objects, but all streams share TCP's ordered byte stream, so a lost TCP segment can delay delivery on every stream.