Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection Pooling with PostgreSQL and AWS

Having a microservices architecture, multiple services speak to my PostgresSQL database. If I now want to deploy parts of my application as AWS Lambda functions, how can I avoid running out of connections?

Reading a couple of articles [1], [2], [3] I realized PgBouncer may be a good fit for my microservice architecture.

Do I need a "microservice" in front of my database? How to set this up with AWS Lambda?

like image 747
lony Avatar asked Feb 21 '16 17:02

lony


People also ask

How do I connect to a Postgres database from AWS?

Sign in to the AWS Management Console and open the Amazon RDS console at https://console.aws.amazon.com/rds/ . Open the RDS console and then choose Databases to display a list of your DB instances. Choose the PostgreSQL DB instance name to display its details. On the Connectivity & security tab, copy the endpoint.

Is PostgreSQL supported by AWS?

AWS supports PostgreSQL through a fully managed database service with Amazon Relational Database Service (RDS). Amazon Aurora with PostgreSQL compatibility is also built using PostgreSQL.

How does connection pooling work in PostgreSQL?

Connection pooling is the process of having a pool of active connections on the backend servers. These can be used any time a user sends a request. Instead of opening, maintaining, and closing a connection when a user sends a request, the server will assign an active connection to the user.

Which AWS service is a relational database compatible with MySQL and PostgreSQL?

Amazon Aurora is a relational database management system (RDBMS) built for the cloud with full MySQL and PostgreSQL compatibility.


1 Answers

According to this thread on AWS developer forum, AWS Lambda try to reuse old process when it's possible, which offers possiblity to use a client connection pooling.

In my opininon, use a dedicated connection pooler in front of your database is always a good idea. With it, you minimize open connection on your database, which can be an resource consumer. You can find more information, for Postgresql, on this blog post

As far as I am aware, AWS doesn't offer a dedicated service for connection pooling. You can use a dedicated instance for this. For Postgresql, PgBouncer is a good option. It doesn't need a heavly cpu or large amount of memory, but you still prefere a network optimized instance. And be careful, with only on instance of PgBouncer, you introduce a spof in your architecture.

like image 194
kletord Avatar answered Oct 08 '22 07:10

kletord