3 ms·
> you can mitigate by using connection pooling Can you do connection pooling to Postgres from cloud functions? I know there is a Node driver that does it for
by pier25 6y ago
> you can mitigate by using connection pooling
Can you do connection pooling to Postgres from cloud functions?
I know there is a Node driver that does it for MySQL [1] but I've never seen one for Postgres.
[1] https://github.com/jeremydaly/serverless-mysql https://github.com/jeremydaly/serverless-mysql
- frompdx 6y agoRun something like PgBouncer in front of your postgres instance. https://www.pgbouncer.org/ https://www.pgbouncer.org/ For what it is worth, the popular postgres and mysql libraries for nodejs support connection pooling out of the box. Cloud functions break this functionality because you are spinning up an instance per connection rather than handling multiple connections with a single instance of nodejs. In this case I think that longer lived containers or vms that can autoscale my be a better solution. That is not to say you should not use cloud functions. I understand they offer many benefits. Managing a fleet of vms or containers introduces its own challenges. In general I think this is a good example of how simplifying one thing can complicate other things. There are no silver bullets. It's all about determining the compromises you can and cannot accept.
- pier25 6y agoThanks for the link to Pgbouncer, I'll check that. I'm using Cloudflare Workers which are distributed on the CF network and run at the edge to reduce latency. Achieving the same thing with containers would be probably complicated and expensive. Right now I'm using Fauna DB which is also distributed and doesn't have connection limits, but I want to explore all my options. Edit: If anyone wants to know more about PGBouncer and pooling with postgres I found this article very informative: https://www.compose.com/articles/how-to-pool-postgresql-connections-with-pgbouncer/ https://www.compose.com/articles/how-to-pool-postgresql-conn...