I'm facing an issue related to MongoDB connections while sending push notifications to users three times a day — morning, noon, and evening.
I have a Lambda-based service that uses SQS and MongoDB. A scheduled cron job send data to SQS and it will trigger these Lambdas at the specified times. The issue arises when about 10 Lambdas are triggered per second, and each one creates its own connection pool with 10 connections, quickly exceeding MongoDB’s connection limit.
To temporarily resolve this, I made the following changes:
Set the SQS batch size to 1
Limited the Lambda reserved concurrency to 1
Set the maxConnectionPoolSize to 1
This workaround is currently functional, but I understand it’s not a scalable or ideal solution.
While investigating this, I noticed that AWS RDS supports RDS Proxy, which helps manage connection pooling and authentication. Unfortunately, MongoDB doesn’t provide an equivalent out of the box.
I’d like to know: Is there a way to build a proxy layer for MongoDB that manages connection pooling across multiple Lambdas? If anyone has experience with this or ideas on how to implement such a solution, I'd really appreciate your insights.
Thank you!