Last Updated: February 25, 2016
·
866
· marcofranssen

Offshore heavy jobs in NodeJS

A best practice is to offshore heavy jobs in Node JS to other processes. This can be done using a messagebus like RabbitMQ or ZeroMQ. For example connect also a c# application to the messagebus to process the message and put the result back on the messagebus so nodejs can return the result. This way you can handle a serious amount of parallel requests.

Example:

Socket.io -> NodeJS -> Message #1 -> RabbitMQ -> c# application Processing
Socket.io -> NodeJS -> Message #2 -> RabbitMQ -> java application Processing
Socket.io -> NodeJS -> Message #3 -> RabbitMQ -> php application Processing
Socket.io -> NodeJS -> Message #4 -> RabbitMQ -> c# application Processing
Socket.io -> NodeJS -> Message #5 -> RabbitMQ -> java application Processing
Socket.io -> NodeJS -> Message #6 -> RabbitMQ -> java application Processing

Socket.io <- NodeJS -> RabbitMQ  <- Message #1 <- c# application Processing
Socket.io <- NodeJS <- RabbitMQ  <- Message #5 <- java application Processing
Socket.io <- NodeJS <- RabbitMQ  <- Message #6 <- java application Processing
Socket.io <- NodeJS <- RabbitMQ  <- Message #2 <- java application Processing
Socket.io <- NodeJS <- RabbitMQ  <- Message #3 <- php application Processing
Socket.io <- NodeJS <- RabbitMQ  <- Message #4 <- c# application Processing

Take into account messages may not be processed in same order as example shows, so add something like sequenceIds to your messages if you require ordering during processing of concurrent messages.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip