Sharing Database Model Layer as Node.js npm package!

Saqib Ullah Siddiqui
2 min readAug 5, 2022

--

Today we are going to share the experience of a separate database model layer for each individual backend service, all services are either Web APIs or communication protocol layers.

In our current scenario, we are developing multiple backend services using the node.js platform. For multiple services, we have multiple teams who are developing backend services that are based on a common database model. So the problem will rise whenever we make changes and add tables to the database end.

Different Model Layer and ORM framework

For any type of update at the database level, we have to update the models’ layer ultimately on each project. Up to this level, each development team has its own coping of the model layer code. One more problem that we were facing was each team was using a different version of the sequelize ORM.

To avoid all these problems we have created an npm package that contains complete and updated details of the database tables in the form of model classes. Now it’s the core responsibility of the database engineering team to update and maintain the npm package with the latest database changes.

To get a clear understanding of the npm package structure, we are sharing the details.

Create npm package based on model classes

It’s very clear in the preceding diagram the npm package is based on the specific sequelize ORM {6.21.3} version rather than each service dev team following their own specification.

The dev team now use npm package

Now we need to replace the model layer from the npm package, nothing will be changed in the core service part.

After implementing the model as a package, all dev teams get their required model version simply by installing the targeted package version in the project.

The official npm package website allows private npm packages as well, but for this option, users need a paid account.

I hope this knowledge sharing below will help you out in your daily development practice.

Thanks!

--

--

Saqib Ullah Siddiqui
Saqib Ullah Siddiqui

Written by Saqib Ullah Siddiqui

I read to know, I write to recall.

No responses yet