The cost of a fresh connection
Opening a TCP connection takes a round trip handshake, and adding TLS takes more. If every request opened a new connection, that setup cost would dominate small requests. Keep alive keeps the connection open after a response so the next request reuses it.
Persistent connections
In HTTP version one point one, persistence is the default; the Connection close header explicitly ends it. Requests on a kept connection are still sent one after another, so a slow response can block those behind it, a problem called head of line blocking.
Connection pooling
A client library keeps a pool of open connections to a host and hands them out to waiting requests:
- It limits the number of simultaneous connections per host to be a good citizen.
- An idle timeout closes connections that sit unused to free resources.
- Pools must handle a server closing a connection mid use and retry on a fresh one.
HTTP version two goes further with multiplexing, sending many streams over one connection without head of line blocking at the HTTP layer.
Key idea
Keep alive reuses a connection to skip repeated handshakes, and connection pooling manages many such reusable connections per host to cut latency.