Keep-Alive

Protocol

Reusing a TCP connection for multiple HTTP requests instead of opening a new one each time. Default in HTTP/1.1. Saves the overhead of TCP and TLS handshakes on every request.

Updated Mar 9, 2026

Full Explanation

Without keep-alive, every HTTP request needs a new TCP connection (1 RTT) and TLS handshake (1-2 RTT). For a page loading 50 resources, that's potentially 150+ round trips of pure overhead. Keep-alive eliminates this by reusing connections.

HTTP/1.1 defaults to keep-alive (you have to explicitly send Connection: close to disable it). The connection stays open for a timeout period after each request, ready for the next one. Most servers set this to 60-120 seconds.

For CDN-to-origin connections, keep-alive is critical. Without it, every cache miss opens a new connection to your origin, adding latency and burning through file descriptors. Most CDNs maintain a pool of persistent connections to your origin. If your origin closes connections too aggressively (short keep-alive timeout), you'll see elevated TTFB on cache misses.

Examples

# HTTP/1.1 keep-alive is default
GET /page.html HTTP/1.1
Host: example.com
Connection: keep-alive  # Optional, already default

# Nginx: configure keep-alive
keepalive_timeout 65;     # Client-side timeout
keepalive_requests 1000;  # Max requests per connection

# Nginx: keep-alive to upstream (critical for CDN-origin)
upstream origin {
    server 10.0.1.100:443;
    keepalive 64;  # Pool of 64 persistent connections
}
location / {
    proxy_http_version 1.1;
    proxy_set_header Connection "";
}

Video Explanation

Frequently Asked Questions

Reusing a TCP connection for multiple HTTP requests instead of opening a new one each time. Default in HTTP/1.1. Saves the overhead of TCP and TLS handshakes on every request.

# HTTP/1.1 keep-alive is default
GET /page.html HTTP/1.1
Host: example.com
Connection: keep-alive  # Optional, already default

# Nginx: configure keep-alive
keepalive_timeout 65;     # Client-side timeout
keepalive_requests 1000;  # Max requests per connection

# Nginx: keep-alive to upstream (critical for CDN-origin)
upstream origin {
    server 10.0.1.100:443;
    keepalive 64;  # Pool of 64 persistent connections
}
location / {
    proxy_http_version 1.1;
    proxy_set_header Connection "";
}

Related CDN concepts include:

  • HTTP/1.1 — The most widely deployed HTTP version. Text-based protocol with persistent connections and chunked transfer encoding. …
  • Latency — The time delay between a request and the start of its response. For CDNs, it's …
  • RTT (Round-Trip Time) (RTT) — The time it takes for a packet to travel from client to server and back. …
  • TCP (TCP) — Transmission Control Protocol. The reliable, ordered, connection-oriented transport protocol underneath HTTP/1.1 and HTTP/2. TCP's three-way …
  • TTFB (Time To First Byte) (TTFB) — The time from the start of a request to receiving the first byte of the …