Question

Connection pools through DigitalOcean managed database cluster or through node-postgres on Next.js web application

Prior to setting up my DigitalOcean managed database cluster I was just using a local PostgreSQL database. I was using the node-postgres (https://node-postgres.com/) package to create a connection pool. I would create one connection pool instance and import that instance into my serverless functions to query the database. However, with the DigitalOcean managed database cluster it is recommended to use the built-in connection pool tool (which uses PgBouncer according to documentation). My question is if I use the DigitalOcean connection pool should I not use a connection pool through node-postgres? Currently I have a connection pool set up through node-postgres in my Next.js web application and a connection pool set up through DigitalOcean. I am not sure if this “double pooling” is bad practice or will cause issues. Thanks and let me know if I need to provide more info.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

Indeed you are right, I don’t think that it is necessary to have double pooling. It would be a matter of a personal preference on weather you want to use the managed PgBouncer or the node-postgres pool.

Personally, depending on the project of course, if it was a PgBouncer instance that I had to manage myself I would probably default to the node-postgres pool, just so that I don’t have an extra service to manage. However as the PgBouncer is part of the Postgres Managed Cluster, it should not add extra operational burden.

One thing to keep in mind is that if you are using the App Platform, is that at the moment unfortunately using Trusted Sources with App Platform and PostgreSQL connection pools is not supported. So if you are using the App Platform that might be a blocker, so you might have to default to node-postgres.

Hope that this helps!

Best,

Bobby