Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to design a sails.js project with microservices architecture?

I learned about microservices from here

Now, I want to use microservices architecture in my next sails.js project.

One way I could think of is:

  1. Breaking my one sails.js application into multiple small sails.js sub-projects/repositories.

  2. Having one controller-model in one sub-project. For example, If we consider simple eCommerce app with entities say User, Products, Orders, etc. then there will be separate sails.js repositories for each of them with respective sails.js model-controller. Then this single sub-repository will from my one microservice.

  3. Each sub-repository then will obviously have its own configs.

  4. These microservices will them communicate with each other using some HTTP node module.

  5. Then writing my own API gateway for routing in node.js, which will be responsible for invoking methods/web-services from these sub-repositories depending on the request from clients.

Is this the best way OR is there alternative way to design your project using microservices architecture?

What will be the best way to implement inter-service communication, API gateway with sail.js? If one microservice designed with above mentioned approach get bigger, and if I have to split it up in 2, how sails.js model should be changed?

like image 685
C.P. Avatar asked Sep 24 '16 05:09

C.P.


People also ask

How do I create a microservices architecture in node JS?

Directly inside the main folder, create a file called server. js . Inside, write the following code: // require express const express = require("express"); //create an app using express constructor const weatherApp = express(); // declare your port const port = 5000; // require routes from the routes.

Why Nodejs is best for microservices?

Node. js uses a modular approach to application development, allowing developers to use the microservices architecture for faster and simpler step-by-step updates. In addition, since the Node. js microservices system is loosely connected and independent, developers will have no problems with its maintenance.


1 Answers

The most important aspect of designing microservices is the separation of concerns which means each microservice will have a defined boundary under which they need to work.

Each microservice is designed to do a defined work so, first you need to find the independent functionalities in you project and try to create a microservice for it.

The most important thing to note is you should first start with a monolithic architecture and if you identify that some functionalities needs to be separated then you can create a microservice out of it.

As far as sails is considered then it is a good candidate for MVC and if the project is monolithic but if the number of microservices is large then it is not a good choice because running large number of microservices with sails.js will consume more of your system RAM.Sails.js internally uses so many libraries which you will not need. You can make a simple microservice with just node.js core modules and they will consume less memory too.

Also when each microservices handles small functionalities so the amount of code will be less and there is no need for mvc arcitecture. you can use less number libraries to create it.

Conclusion

  1. If number of services is less and you don't worry about system RAM then go for multiple sails application.
  2. If number of services going to be more then try to make your services without using sails
like image 87
selftaught91 Avatar answered Sep 21 '22 02:09

selftaught91