I am facing performance issues with Prisma with MONGODB. How can I improve the performance?

286 views Asked by At

I used to use only MONGODB as database and mongoose in NodeJs to access it. I recently started using POSTGRES and MONGODB both in my recent project and then learnt about wonders of PRISMA. I integrated it into my project and created schemas. Once I started using it I noticed that MONGODB crud operations were exponentially slower than mongoose calls.

Few of the reasons I think might the issue be are:

  1. For Prisma to support NoSQL databases, they added an extra layer of validation, this extra layer is slowing it down.

  2. Every time I run a query will it create a new connection with database and then perform action. If so that is an expensive operation.

  3. We might have many indexes or uniques which might slow down the database.

These are few of the reasons that I can think of and if there are any other reasons, feel free to suggest.

I tried creating a 1000 documents using PRISMA and Mongoose. The results are:

PRISMA took **1 min 31 sec**
Mongoose took **10.91 sec**

I tried creating 1000 records in POSTGRES. The result is:

PRISMA took **4.37 sec**

I expected the output to be faster in MONGODB because I will be saving something like transactions which happen quiet often in this environment. Hence if there is a lag then it will slowdown the whole server.

I used thunder client to benchmark these results and performed API calls to test it.

What might me the possible resolutions for this problem?

If there are any queries feel free to ask.

Environment:

Prisma: 5.4.2 TypeScript: 5 @types/express: ^4.17.19, @types/node: ^20.8.4

0

There are 0 answers