HTTP Persistent and Non- Persistent Connections

Introduction

Hello, if you are reading this article you are using the internet either through the web browser or the Hashnode application. You know that the content displayed on your device is obtained from a remote computer called a web server, but do you know how the content is transferred from the server to your device? In this article am going to explain the two types of HTTP connections, their differences, and the advantages of each type. By telling the advantages we will be able to choose which one is better.

How the Web Works

First of all, let's get to know how the web works. The web server stores files which are called objects. The files may be images, videos, documents, and audio including Javascript, HTML, and CSS files. To get these files your device fires up an HTTP connection to the server. After the connection is established, the client device(your device) using HTTP protocol sends an HTTP request to the web server like GET, HEAD, and POST to mention a few. The web server processes the request and responds by sending the requested object to the client. The client web application processes the received objects and displays the content to you.

The concept of persistence and non-persistence connection comes into play when the connection is being established and the objects are being transferred between the web server and the client.

Non-Persistent HTTP Connection

Non-persistent HTTP connection, this mode of connection establishes a new connection for every request and closes it after the client is served. Every object uses its connection. If there are five files and the client makes five requests to get the files, it means that five connections will be established between the server and the client. The name 'non-persistent' says it all, the connection does not persist, and it is renewed for each request sent by the client.

Advantages of Non-Persistent HTTP Connection

  1. Better Resource Utilization: Non-persistent connections are more suitable for serving small files, as they do not tie up server resources for a long time. This means that the server can handle more requests from more clients in the same amount of time.

  2. Improved Cacheability: Non-persistent connections are more cache-friendly than persistent connections, as each request can be cached independently. This improves the caching efficiency and reduces the server load.

  3. Simplicity: Non-persistent connections are simpler to implement and require less overhead in terms of coding and testing. They are easier to manage and debug, and they work well in low-bandwidth environments.

  4. Compatibility: Non-persistent connections are supported by older web browsers and legacy web applications that do not support persistent connections. They are more compatible with older web infrastructure.

Persistent HTTP Connection

A persistent HTTP connection, as the name says, is a connection that is made once and last until all the objects are transferred. All objects are transferred using the same connection. Unlike non-persistent HTTP connection which establishes a new connection for each object all objects requested by the client use the same connection to get to the client from the server. This means that the connection is fired up once and it serves all requests sent to the server by the client.

Advantages of Persistent HTTP Connection

  1. Reduced Latency: Since the connection is already established, the time required to establish a new connection is saved. This reduces the overall latency and improves the response time of subsequent requests.

  2. Reduced Network Overhead: Each TCP connection requires an overhead to establish and terminate the connection, which adds additional load on the network. Persistent connections help reduce this overhead by reusing the same connection for multiple requests.

  3. Improved Efficiency: Persistent connections allow the client to pipeline requests, which means that the client can send multiple requests to the server without waiting for each response. This improves the efficiency of communication.

  4. Better Server Resource Utilization: Since the server does not have to create a new connection for each request, it can handle more requests with the same resources. This improves the scalability of the server

Final Words

Having a look at both modes of HTTP connection, we can say the Persistent HTTP connection has a big win over its elder brother, the Non-persistent HTTP connection. A non-Persistent HTTP connection though older is not useless, it can be used to integrate services that use old web architecture with the services which run modern architecture.