Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to communicate between two servers?

I am building a web app which has two parts. In one part it uses a real time connection between the server and the client and in the other part it does some cpu intensive task to provide relevant data.

Implementing the real time communication in nodejs and the cpu intensive part in python/java. What is the best way the nodejs server can participate in a duplex communication with the other server ?

like image 849
Sanjit Roy Avatar asked May 04 '15 10:05

Sanjit Roy


2 Answers

For a basic solution you can use Socket.IO if you are already using it and know how it works, it will get the job done since it allows for communication between a client and server where the client can be a different server in a different language.

If you want a more robust solution with additional options and controls or which can handle higher traffic throughput (though this shouldn't be an issue if you are ultimately just sending it through the relatively slow internet) you can look at something like ØMQ (ZeroMQ). It is a messaging queue which gives you more control and lots of different communications methods beyond just request-response.

When you set either up I would recommend using your CPU intensive server as the stable end(server) and your web server(s) as your client. Assuming that you are using a single server for your CPU intensive tasks and you are running several NodeJS server instances to take advantage of multi-cores for your web server. This simplifies your communication since you want to have a single point to connect to.

If you foresee needing multiple CPU servers you will want to setup a routing server that can route between multiple web servers and multiple CPU servers and in this case I would recommend the extra work of learning ØMQ.

like image 78
Jedediah Smith Avatar answered Sep 19 '22 03:09

Jedediah Smith


You can use http.request method provided to make curl request within node's code. http.request method is also used for implementing Authentication api. You can put your callback in the success of request and when you get the response data in node, you can send it back to user. While in backgrount java/python server can utilize node's request for CPU intensive task.

like image 41
binariedMe Avatar answered Sep 22 '22 03:09

binariedMe