← Lessons

quiz vs the machine

Platinum1780

Networking

Connection Keep Alive and Pooling

How reusing TCP connections avoids repeated handshakes and speeds requests.

5 min read · advanced · beat Platinum to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. What does keep alive avoid repeating for each request?

2. What problem can occur when reusing a single persistent connection serially?

3. What is the purpose of a connection pool's idle timeout?