Sunil Kumar Profile picture
29 Oct, 10 tweets, 2 min read
DATABASE CONNECTION POOLING is one of the import concepts to know for every Software Developer (both front-end and back-end).

You should know how REST services are optimised using database connection pooling.

Let's discuss it in this thread 🧵👇🏻
Let's say you have a backend service which has an API endpoint to read data from a database table.

This is how a naive developer would implement such an endpoint:

- open db connection
- read the data from database
- close db the connection
- return the response

Now there's nothing wrong with implementing it this way. The end point works perfectly fine and it returns the desired results.

The problem is when you get so many concurrent requests.

Every API call is going to open a database connection and that's not good because...

... generally opening a DB connection, closing a DB connection are generally time intensive operations. So the overall latency of your API increases.

Also you don't have any control over how many connections are created.

Let's say there's a bug in your code and you end up creating too many connections in a loop. This will case the database to go down.

This is not good if the database is shared across multiple teams in your organisation. Every product would be affected in this case.

This is where database connection pooling comes into the picture.

Basically we create a pool of DB connections during service initialisation. Three main parameters involved here are:

1. Max pool size: The number of connection to be created in the pool

2. Connection Timeout: If all the connections in the pool are busy, for how long a client should wait until the next connection becomes available.

3. Idle Timeout: Idle timeout is the timeout after which a database connection is released after being in the idle state.

Now let's discuss how connection pooling will solve the problems we discussed above.

1. Since we're creating db connection during service initialisation, we don't do time intensive operations like connection creation, connection release etc for every API call.

This reduces the API response time drastically and thus improving the overall performance of your service.

2. We have control over how many total database connections are created. Even if there's a bug in the code we will not end up creating a large number of connections.

I hope you now understand what database connection pooling is and why it's important in a REST service.

If you like this thread consider subscribing to my blog where I generally write detailed articles on topics like

- coding
- aws
- freelancing
- SaaS

• • •

Missing some Tweet in this thread? You can try to force a refresh

Keep Current with Sunil Kumar

Sunil Kumar Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!


Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @sunilc_

31 Oct
Are you a JavaScript developer and Game Development enthusiast?

Here's a list of JavaScript game engines you should check out:

1. three.js

JavaScript 3D library.
2. pixi.js

The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.
Read 11 tweets
30 Oct
Micro Services Architecture Vs Monolith Architecture:

You might have heard about these terms again and again. But what are they, their advantages and disadvantages?

Let's discuss it in this thread: 🧵👇🏻 Image
Micro Services Architecture:

Micro Services is an architectural style where a single application is built as a suite of multiple smaller services which are loosely coupled, maintainable and scalable separately.

Let's discuss what that means.

Let's take the below example:

As you can see, our example application takes care of user accounts, reading and updating inventory and shipping the products to end users.

👇🏻 Image
Read 16 tweets
27 Oct
Are you a freelancer and struggling to manage your time between different projects & clients?

Here's a list of tools and resources to help you organise your work:

1. Beagle: A tool for creating better contract proposals
2. Funnel: A CRM for small businesses and freelancers
Read 6 tweets
26 Oct
Are you a front-end developer?

These design libraries will help you create stunning products on the web:

1. Bootstrap: The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.

2. Animate.css: 🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.…
Read 14 tweets
24 Oct
Do you want to start making money through Freelancing but struggling to get started?

Here are some tips for you to get started and grow from there:

Most people struggle to get their first freelancing task. I used to think I may never be able to earn any money through freelancing with my skills (until last year).

But freelancing is not difficult at all!

You just have to go through the barrier of getting that first task.

Once you complete your first task, there's no stopping you.

Know that even 👉🏻 YOU can make a lot of money through freelancing!

Here are some tips to land your first task and how to grow from there:

Read 15 tweets
23 Oct
Are you a Python Developer & an Open Source enthusiast? 🐍

Here's a list of Python open source projects you can contribute to:

1. Tensorflow ( ⭐️ 149k )…
2. Youtube dl ( ⭐️ 72.2k )…
Read 16 tweets

Did Thread Reader help you today?

Support us! We are indie developers!

This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!