Reputation: 21
I am using Payload CMS (v3.20.0) with Next.js 15, deployed on Vercel (serverless runtime), and using MongoDB Atlas (M2 cluster) as my database.
Problem Each time I refresh my home page, I receive the following alert from MongoDB Atlas:
You are receiving this alert email because connections to your cluster(s) have exceeded your threshold and are nearing the connection limit for the M2 cluster (Cluster0) in the Project (Project 0) within Organization.
My MongoDB connection limit is 400, and I can see that the number of connections spikes every time the page is refreshed.
What I Have Tried Ensured a single database connection instance: I am using Payload CMS with the default MongoDB connection settings, but I'm concerned that serverless deployments on Vercel might be opening new connections for each request. Checked Payload CMS settings: I looked into how Payload handles database connections but couldn't find a built-in solution to reuse connections efficiently. Investigated Vercel's serverless behavior: Since Vercel uses ephemeral functions, I suspect that each function execution creates a new database connection. Questions How can I ensure Payload CMS reuses MongoDB connections instead of opening new ones on each request? Is there a recommended approach to optimize MongoDB connections for Payload CMS when deployed on a serverless platform like Vercel? Would switching to a dedicated MongoDB Atlas cluster (M10+) be the only solution, or is there a way to manage connections efficiently within the M2 plan? Any guidance on handling MongoDB connections efficiently in this setup would be greatly appreciated!
Upvotes: 1
Views: 41