Search code examples
node.jsexpressrabbitmqmicroservicesload-balancing

When use rabbitMQ in node REST API?


I have developed a node sdk which has certain REST API.These API's are interacting with blockhchain framework for read and write operations. There could be certain situations when many requests are coming on node sdk. So for load balacing i have used NGNIX with having one more replica of sdk on another instance.This all works well.

It is being suggested to use rabbitMQ for load balancing as well. But in my API there are few straightforwards read and write operations by API & no heavy processing done.

I read rabbitMQ should be used for below purpose.

  • Integrating multiple microservices
  • Executing heavy task such as image processing,image uploading etc.

So how and when should i use rabbitMQ ?


Solution

  • I think your design is OK. Simply, your system had to manage more load and you added more replicas of your services, with a load balancer on the front that is able to distribute incoming load between the replicas. If your "sdk" is purely stateless (doesn't remeber client data collected from previous requests, but delegates all state to a DB/BC) your've done your job. A message queuing technology can help in other scenarios

    1. when your application does things in a pure asynchronous fashion
    2. when you have to manage big spikes of load
    3. when some of your architecture component reacts to events (eg. receiving an alarm from a device, sending an email when your become the 1 million click etc)
    4. when you're into event sourcing
    5. when in some way there are stateful services that consume data from the same batch of requests (eg all data from user with id 1sw023)
    6. various and possible

    Adopting MQs has a big impact and needs some effort to integrate e manage things. Don't do it if you are not sure to leverage completely its benefits