DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
  1. Home
  2. Articles
  3. Frontend Engineering
  4. HTTP Connection Keep-Alive: What It Does and Why It Matters
XLinkedInReddit
MediumFrontend Engineering

HTTP Connection Keep-Alive: What It Does and Why It Matters

D
DevPrep Team
February 9, 2026·2 min read·0
Table of Contents
  • The Problem Keep-Alive Solves
  • How It Works
  • Keep-Alive vs HTTP/2 Multiplexing
  • Real Production Impact
  • Connection Limits
  • CDN and Domain Sharding (Legacy)
  • When to Disable Keep-Alive
  • Best Practices
  • Summary

By Rahul — Google Frontend Engineer

The Problem Keep-Alive Solves

In HTTP/1.0, every request opened a new TCP connection. Loading a page with 30 resources meant 30 TCP handshakes. Each handshake takes 1 RTT (round-trip time). On a 100ms latency connection, that is 3 seconds just for handshakes.

// HTTP/1.0 without Keep-Alive
Request 1: [TCP handshake] [Request] [Response] [Close]
Request 2: [TCP handshake] [Request] [Response] [Close]
Request 3: [TCP handshake] [Request] [Response] [Close]

// HTTP/1.1 with Keep-Alive (default)
[TCP handshake]
Request 1: [Request] [Response]
Request 2: [Request] [Response]
Request 3: [Request] [Response]
[Close after idle timeout]

How It Works

In HTTP/1.1, Connection: Keep-Alive is the default. The TCP connection stays open after a response, and subsequent requests reuse it. The server closes the connection after an idle timeout or after a maximum number of requests.

// Request header
Connection: Keep-Alive
Keep-Alive: timeout=5, max=100

// timeout=5 — close after 5 seconds of inactivity
// max=100 — close after 100 requests on this connection

Keep-Alive vs HTTP/2 Multiplexing

Keep-Alive in HTTP/1.1 has a limitation: head-of-line blocking. You must wait for a response before sending the next request on the same connection. HTTP/2 solves this with multiplexing — multiple requests and responses can fly simultaneously on the same connection.

// HTTP/1.1 Keep-Alive — serial
[Request A] → [Response A] → [Request B] → [Response B]

// HTTP/2 — parallel on same connection
[Request A] →              → [Response A]
[Request B] → [Response B]
[Request C] →         → [Response C]

Real Production Impact

Connection Limits

Browsers allow only 6 TCP connections per domain in HTTP/1.1. With Keep-Alive, these 6 connections are reused. Without it, you would need a new connection for every request, hitting the limit constantly.

CDN and Domain Sharding (Legacy)

Before HTTP/2, engineers used domain sharding — serving assets from multiple subdomains to get more parallel connections:

<img src="https://img1.example.com/a.jpg" />
<img src="https://img2.example.com/b.jpg" />
<img src="https://img3.example.com/c.jpg" />

With HTTP/2, domain sharding actually hurts performance because you lose the benefit of multiplexing over a single connection.

When to Disable Keep-Alive

Almost never. But there are edge cases:

  • Load balancers that need to redistribute connections
  • Server under memory pressure with too many open connections
  • Single-request APIs where the overhead of maintaining connections is not worth it

Best Practices

  • Use HTTP/2 — it makes Keep-Alive's limitations irrelevant
  • Do not use domain sharding with HTTP/2
  • Set reasonable idle timeouts on your servers (5-15 seconds)
  • Monitor open connection counts in production

Summary

Keep-Alive reuses TCP connections to avoid repeated handshakes. It is the default in HTTP/1.1. HTTP/2 takes this further with multiplexing. As frontend engineers, we benefit from this automatically, but understanding it helps debug slow page loads.

Related Articles

MediumFrontend Engineering

System Design #12: Design a Multi-Step Form Wizard

7 min read
MediumFrontend Engineering

Mastering Senior-Level JavaScript Interview Concepts

2 min read
MediumFrontend Engineering

System Design #9: Design a Collaborative Text Editor

9 min read

Comments (0)

Sign in to leave a comment.

No comments yet. Be the first to comment.

Table of Contents

  • The Problem Keep-Alive Solves
  • How It Works
  • Keep-Alive vs HTTP/2 Multiplexing
  • Real Production Impact
  • Connection Limits
  • CDN and Domain Sharding (Legacy)
  • When to Disable Keep-Alive
  • Best Practices
  • Summary

Series

View all Frontend Engineering articles →

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.