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?
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.
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.
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.
Amazon Aurora is a relational database management system (RDBMS) built for the cloud with full MySQL and PostgreSQL compatibility.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With