Connection Pooling

Mohak Puri
2 min readDec 31, 2020

This article is part of a series that I have started working on. In this series, I’ll be briefly discussing engineering concepts.

1/n

What

Connection pooling is re-using a bunch of connections instead of creating a new connection for every request.

Why

  1. TCP connections are costly → Creating a TCP connection requires a 3-way handshake. It takes time and resources to create one.
  2. TLS → With HTTPS there is an overhead of TLS handshake.
Credit: Cloudflare

Demo

Let’s see what happens when we use the same connection for multiple requests.

These requests need to be to the same domain

Run the following command

curl https://github.com/404 https://github.com/404 -o /dev/null -w '\nEstablish Connection time %{time_connect} total time %{time_total}\n'
Request 1 creates a new connection
Request 2 on the same connection

As you can see the 1st request involves TLS termination but the 2nd request completely skips it since it is using the same connection.

Total time and Time taken to establish a new connection

Also, the time take to establish a connection is very less for the 2nd request as compared to the 1st one.

That’s about it! Thank you for reading, and I hope you enjoyed the article. If you did make sure to give it a clap :)

You can also follow me on Medium and Github. 🙂

--

--

Mohak Puri

Lead Software Engineer @INDmoney | ex GO-JEK | GSoC 2018 @openMF | Mobile | Backend | mohak1712 everywhere