Cloud Technology

How do you handle database connection pooling in high-scale Lambda functions?

KA Asked by Karen White · 12-04-2024
0 upvotes 14,841 views 0 comments
The question

We are hitting "Too Many Connections" errors on our RDS Postgres instance during traffic spikes because our Lambda functions don't share a connection pool. We’ve tried RDS Proxy, but the latency overhead is noticeable. Is there a better way to manage database scaling for serverless apps in 2024? 

3 answers

0
NA
Answered on 18-04-2024

RDS Proxy is usually the standard answer, but if you're sensitive to that extra 10-15ms of latency, you might want to look at a "Connection Concentrator" like PgBouncer sitting on a small EC2 instance, though that adds management. Alternatively, have you considered moving to a truly serverless database like Aurora Serverless v2 or DynamoDB? Aurora v2 handles the scaling much more gracefully than a traditional RDS instance. We actually moved our high-frequency write operations to DynamoDB and kept the relational data in RDS, which significantly reduced the connection pressure.

0
KE
Answered on 22-04-2024

Are you using a specific ORM like Prisma or TypeORM? Some of them have "Serverless-friendly" modes that help manage connections more efficiently. 

BR 25-04-2024

Kevin, we are using Prisma. We actually found that the "Prisma Data Proxy" helped quite a bit with connection management without the complexity of AWS's native proxy. However, we eventually realized our Lambdas were staying "warm" too long and not releasing connections. We adjusted the idle_timeout in the DB settings, which cleared up the hanging connections. It’s a bit of a balancing act between Lambda warm-up speed and DB connection limits.

0
SA
Answered on 28-04-2024

Sometimes the simplest solution is just to scale up the RDS instance size to get a higher max_connections limit. It’s brute force, but it works if you have the budget. 

KA 01-05-2024

Sarah is right, but it's an expensive band-aid. We found that optimizing our Lambda execution time actually helped more, as it freed up the connections faster for the next request.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

World globe icon Country: India

Book Free Session