← Back to list

HTTP Keep-Alive: How do the server and client continue their relationship?

It’s simple to start and end a new relationship, but keeping it going over time can be challenging. The same concept applies to digital…

Uzman Arfan · 2024-10-18 04:52 · 0 claps · 4.6 min read
#http-status-code #network #http-keep-alive #http-version
Open on Medium ↗
Wiki topics: 💑 · Relationships

HTTP Keep-Alive: How do the server and client continue their relationship?

It’s simple to start and end a new relationship, but keeping it going over time can be challenging. The same concept applies to digital systems. To ensure efficient communication, the connection between a server and client must be nurtured and maintained, just as it is with human relationships. Here is where HTTP Keep-Alive comes into play.

In this blog, we’ll look at how HTTP Keep-Alive works and why it’s so important for keeping the server and client in good working order.

What is HTTP?

Before we dive into Keep-Alive, it’s essential to understand HTTP (Hypertext Transfer Protocol), the foundation of data communication on the World Wide Web. HTTP defines how messages are formatted and transmitted between web browsers (clients) and servers.

It was developed by Tim Berners-Lee and his team between 1989 to 1991, and has gone through many changes that have helped maintain its simplicity while shaping its flexibility

A Brief History of HTTP

HTTP/0.9 (1991): The first version of HTTP, limited to fetching HTML files with no status codes or headers. It was simple but impractical for the growing web.

HTTP/1.0 (1996): A fully documented version with the ability to transfer more than just HTML, but required a new TCP connection for every resource request, which was inefficient.

HTTP/1.1 (1997): Introduced persistent connections (Keep-Alive) by default, allowing TCP connections to remain open for multiple requests. However, it suffered from a problem known as Head-of-Line (HOL) blocking — where one slow request could hold up others in the queue.

HTTP/2 (2015): Solved the HOL blocking issue at the application level by introducing multiplexing, allowing multiple requests over a single TCP connection simultaneously.

HTTP/3 (2020 draft): Replaces TCP with QUIC (built on UDP), eliminating HOL blocking at both the application and transport layers, and improving connection speed and reliability.

Reference: https://www.linkedin.com/pulse/http-10-vs-11-20-30-swadhin-pattnaik/

To learn more about how data flows through a network from client to server and server to client, see my blog below.

[embed]Understanding the OSI Model — We often discuss but struggle to understand this… Imagine you’re sending a postcard to a friend who lives halfway around the world. This postcard must go through several…uzmanarfan.medium.com

How Long Will We Last? Persistence vs. Non-Persistence

HTTP has two main connection modes:

  1. Non-Persistent Connection: Used in HTTP/1.0, where each request requires a new connection. This can lead to high latency and increased load on the server, as it must handle multiple short-lived connections.
  2. Persistent Connection (Keep-Alive): The default in HTTP/1.1, where the connection remains open, allowing multiple requests to be sent over the same connection, significantly reducing overhead.

Source: https://en.wikipedia.org/wiki/HTTP_persistent_connection

Source: https://en.wikipedia.org/wiki/HTTP_persistent_connection

In a persistent connection, the server maintains the relationship with the client until either the connection times out (due to inactivity) or the server decides to close it. The timeout period can be configured based on the needs of the application. For example, setting a timeout that’s too long could lead to unnecessary resource consumption, while too short a timeout might close the connection prematurely, negating the benefits of Keep-Alive.

How HTTP Keep-Alive Extends the Relationship

Much like nurturing a long-term relationship, HTTP Keep-Alive helps maintain the connection between the server and client by reusing the same channel of communication for multiple interactions. This is achieved via HTTP headers, particularly the Connection: Keep-Alive header in HTTP/1.0, and by default in HTTP/1.1.

Keep-Alive Headers

  • Client request headers: The client can include Connection: Keep-Alive in the HTTP request to inform the server that it prefers the connection to stay open.
  • Server response headers: If the server supports Keep-Alive, it can respond with Connection: Keep-Alive in its headers, along with optional parameters like Keep-Alive: timeout=5, max=100, which controls how long the connection stays open and how many requests it will allow before closing.

Advantage of using a keep-alive signal

  1. Improved TCP efficiency: By avoiding the overhead of repeatedly setting up and tearing down TCP connections, Keep-Alive enhances the efficiency of data transfers.
  2. Lower latency: Since no new TCP handshake is needed for each request, the time required to load web pages, especially those with multiple resources, is reduced.
  3. Reduced network congestion: By reusing existing connections, fewer network packets are required, reducing congestion and improving overall network performance.
  4. Increased web page speed: Faster data transfers lead to quicker page load times, improving user experience.
  5. Energy and resource savings: Both the client and server consume fewer resources since they aren’t constantly negotiating new connections.

Limitations in using keep-alive signal

  1. Resource usage: Keeping multiple connections open can consume significant memory and CPU resources, especially on busy servers.
  2. Timeout management: If a connection is kept alive for too long without being used, it may tie up server resources unnecessarily, potentially leading to resource exhaustion.
  3. Not effective for HTTP/2 or HTTP/3: As HTTP/2 and HTTP/3 introduce multiplexing and improved transport layers, Keep-Alive becomes less critical since these protocols can handle multiple requests more efficiently over a single connection without the need for persistent connections.

Conclusion

HTTP Keep-Alive is an important mechanism in modern web communication because it ensures that the client-server relationship is maintained effectively and efficiently. Using the same connection for multiple requests reduces latency, increases page speed, and optimizes resource usage on both sides of the connection.

Keep-Alive, like any other relationship, needs to be managed properly. Setting appropriate timeout values and knowing when to close connections are critical to reaping the benefits while avoiding potential drawbacks.

Keep-Alive becomes less necessary as newer versions of HTTP evolve (such as HTTP/2 and HTTP/3), but it remains a powerful tool for HTTP/1.1 and legacy systems to maintain a strong and long-lasting server-client relationship.

References

[embed]HTTP persistent connection - Wikipedia HTTP persistent connection, also called HTTP keep-alive, or HTTP connection reuse, is the idea of using a single TCP…en.wikipedia.org

[embed]HTTP Keep-Alive - In Light HTTP keep-alive is a feature that allows a client to connect repeatedly to a server without disconnecting prematurely…www.atatus.com

https://www.cloudflare.com/learning/ddos/glossary/hypertext-transfer-protocol-http/


메타데이터
post_id
1ed681d64d82
slug
http-keep-alive-how-do-the-server-and-client-continue-their-relationship-1ed681d64d82
url
https://medium.com/@uzmanarfan/http-keep-alive-how-do-the-server-and-client-continue-their-relationship-1ed681d64d82
canonical_url
https://medium.com/@uzmanarfan/http-keep-alive-how-do-the-server-and-client-continue-their-relationship-1ed681d64d82
author_url
https://medium.com/@uzmanarfan
status
ok
fetched_at
2026-08-06 17:37:03