0

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!

3
  • How many connections can you handle? How many concurrent lambdas would run? Why would a lambda need a connection pool size of anything other than 1, are the lambda functions themselves sending multiple requests in parallel? Commented Jul 19 at 16:19
  • I don't think that there is anything built in on mongodb side. The recommended approach for using mongodb client + aws lambda is to save created client in static field at least in languages like java or c# Commented Jul 22 at 17:58
  • see also mongodb.com/docs/atlas/manage-connections-aws-lambda Commented Jul 22 at 17:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.