Mongoose DB connection very slow sometimes - Next.js (serverless w/ Vercel)

I am using Next.js, deployed to Vercel’s serverless platform. Mongoose is the ORM.
I am seeing connection times of ~1s and unsure why it is taking so long just to connect to the DB?

Where is your mongo server hosted? Is it an Atlas instance and if so what type is it?

Can you reproduce the connection times when running locally as well as on Vercel’s platform?

I am using a dedicated M10 Atlas instance with the default 3 servers. Yes, I can replicate the connection time in local. P75 is under 1MS, P95 is +500ms.

Hi

Did you find a solution, I have the same problem

1 Like