Replies: 2 comments 7 replies
-
This is kind of a problem with all databases in the serverless world, as they all require persistent connections and thus can suffer from connection pool issues. Products like PlanetScale and Prisma Data Platform help solve this for SQL DBs (with very low connection limits), but unless you're receiving an enormous amount of traffic on your API routes, I'm wondering why you are hitting the 500 connection limit here? It might be worth looking into how long each query is taking, as 500 requests on a poorly performing query could do this no matter what serverless framework you're using. Is everything indexed? Are you using aggregations? |
Beta Was this translation helpful? Give feedback.
-
Keeping Database connection a live throughout entire lifecycle of your application to avoid resource exhausted and effective managing of single connection in all requests is key to improve your app performance and overall usability of your app. take a look my in depth analysis of how you can do this by implementing Singleton Design pattern in Nextjs👇 |
Beta Was this translation helpful? Give feedback.
-
So I have a number of API files that need to connect to mongodb, unlike when I run a NodeJS app I can put the mongodb connector inside the app.js file which opens and then I can connect to that connector.
However it seems that in NextJS every time I run the api code it is making a new connection which is causing me to reach my limit of 500 connections.
I am using the native MongoDB NodeJS drive.
I am using the following (every time the page is requested - so no wonder it is making a new connection. is there a better way to do this?
In a native NodeJS app we do it like this
app.js
then in ./api/users
But this does not seem to work in _app.js for NextJS
Beta Was this translation helpful? Give feedback.
All reactions