Creating a connection pool for Snowflake

Have you ever tried to query Snowflake from your web application? You might have noticed that your queries are taking longer than you expected from the app. The reason for this is you are creating a new snowflake connection every time there is a request from your web app. This adds an additional overhead of ~2s for each request. In this article, we will see how to create a connection pool for snowflake so that you can utilize the same connections to make the queries rather than creating new connections for every request.

I’ve implemented the connection pool on NodeJS, but you may use the language of your choice and the concept will remain the same. So let’s get started!

~ npm install --save snowflake-sdk
~ npm install --save generic-pool

2. Create a file snowflake.js and add the following code

Let us understand what we have done here

3. Add the following code to utilize the connection

We can utilize the pool and query using a connection from the pool by importing the snowflake.js file and calling the query function.

Some findings on connection pool :

That's all there is for creating a connection pool. Let me know your thoughts and if you have any questions in the comments below!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store