Home > Software engineering >  Is it possible to perform rolling index update with prisma on MongoDB?
Is it possible to perform rolling index update with prisma on MongoDB?

Time:11-20

Prisma requires mogodb to run in a replica set for some of the transactions work. This means that in theory some expensive and blocking index updates can be performed on a rolling bases i.e. made to replicas first and replica then promoted to be primary.

I tried using prisma db push and it appears it applies indexes to primary database (my database was not available for some time while indexes were being pushed).

I was wondering if it is possible to perform this rolling index update using prisma, thus allow zero downtime?

CodePudding user response:

No.

Prisma is an ORM meaning that it assists interacting with data in the database. It is not responsible for management or operation of the database.

This is relevant because MongoDB does not support a command to perform index builds in a rolling manner across the replica set. Instead, that procedure is a technique that operators can elect to follow when building indexes. The procedure is outlined here.

Although that functionality is not built into the database itself, managed solutions can optionally build it into their offering. Likely the closest you can get to perform a rolling index build programmatically is to leverage an API that triggers the procedure via the managed solution. For reference, it looks like Atlas offers such an endpoint here.

All that said, MongoDB has made some changes to their index build procedures in recent years. It used to be the case that indexes were built in the foreground. This was a blocking operation and could cause behavior similar to what you described (where the database was unavailable for some time). There was the ability to specify that indexes be built in the background to reduce the impact in those versions.

Since version 4.2, there is no longer the ability to build indexes in the foreground. Since then, index builds behave more similar to how they previously did when using the background option. More information is available here. So the impact of building indexes through Prisma (or any client drivers) should at least be reduced in version 4.2 of MongoDB compared to previous versions.

  • Related