Backend Engineering

Multiplexing, Demultiplexing (HTTP1.1/HTTP2), & Connection pooling

brian | Published: Feb. 26, 2024, 2:10 p.m. | Updated: May 25, 2025, 2:25 p.m.

Profile Picture

Multiplexing

Multiplexing is the process of combining multiple signals or data streams into a single signal, transmitted over a shared medium or communication channel. in short multiplexing allows our browser to send multiple requests over the same connection, and return the responses in any order

 

 

 

Multiplexing in HTTP1.1

Lets say you make 3 requests to an HTTP1.1 server through the chrome web brower. Once you do that, chrome will open 3 connections, and every single request that's produced, will go into one of these connections.

Pros: Simplcity, and compatible with almost all web servers

Cons: HTTP/1.1 relies on multiple TCP connections to fetch resources in parallel, which can lead to inefficient use of network resources, increased latency due to TCP slow start, and higher server load.

 

 

 

 

Multiplexing in HTTP2

In HTTP2, there can be multiple streams of data that are contained within a single tcp connection. Basically you can multiplex all the requests into one tcp conection.When multiple HTTP requests are sent over a single TCP connection in HTTP/2, each request is assigned a unique stream identifier. This allows the client and server to multiplex multiple requests and responses over the same connection without waiting for previous requests to complete.

Pro:

Example: lets say you load up a website; the browser will ask the web server for an image, maybe another image, maybe 3 other files, and finally the css. All of this while only utilizing one single connection, which is beneficial because now you don't have to wait for a free connection.

 

Cons: In HTTP/2, multiple HTTP requests and responses can be interleaved and sent over a single TCP connection. However, head of lining blocking ( HOL )  can occur when one of these streams is delayed or blocked, causing subsequent streams to be held up behind it, even if they could be processed independently.

 

 

Demultiplexing

Demultiplexing is the reverse of multiplexing,it involves seperating the combined signals, back into individual signals

 

 

 

 

Connection Pooling

In software engineering, a connection pool is a cache of database connections maintained so that the connections can be reused when future requests to the database are required.

Initially a pool of connections are established, and when you make request to the data base, it uses one of the free connections in the pool. Once the query to the data base has finished, the client will return the connection to the pool for future requests, and this makes it so that if we need to make another data base query we wont need to establish a new connection again.

Pros: Cuts down the amount of time the user must wait to establish a connection to the data base

 

Connection pooling in django is created with every single request, and then closed at the end of each request. This is the default behavior in django, but you can modify it in the settings.py file with the " CONN_MAX_AGE "  parameter.