Integrate nodejs (frontend) and C, Erlang, Go ... (backend) [closed]

3

I have a system to be developed that will need to handle a large number of simultaneous requests, where each of these requests will probably involve some task that requires a lot of processing. By researching how to deal with this situation I came to the (obvious?) Conclusion that the solution would be to delegate tasks that require more processing for a written program in a language suitable for that. Layman as I am, I had the idea of replacing PHP with nodejs and letting the server redirect requests for pages and static elements to nodejs, and after the loaded page any heavy task would be requested via ajax and the server would redirect those requests to the programs written in a compiled language.

I would like to: 1 - Opinions. Is this really a smart decision? Viable? 2 - How could I make this integration between the two or more languages?

Note: I can program in PHP. The other languages would involve studies, and / or hiring.

The idea of changing PHP by nodejs came from some research that indicated that the latter is more efficient in dealing with simultaneous requests, in case I am wrong, please let me know. Thanks

    
asked by anonymous 09.03.2016 / 21:37

1 answer

3

There are some possibilities for working with requests that require heavy processing. I will base my answer assuming you are using nodejs as the frontend server.

First you will have to decide if the request that requires processing will be synchronous (user waits for server response) or asynchronous (user sends the request and forgets it ... at some point the server finishes processing and sends a notification to the server. client, by websocket or long pooling of the client).

Based on the answer to the previous question, the architecture of your back will be different. If you choose to do synchronous, you have to ensure that the response will not take too long to generate. So I think the best option in this case is to make a compiled library and wrap it to the nodejs and make the direct call on the node. In case you have chosen the asynchronous option. You can choose to use queues to distribute the processing load to other processes and leave the nodejs server free to understand other requests.

When using a queue nodejs would throw the messages containing the information needed to process into the queue and other processes would be monitoring the queue to get those messages and actually do the processing.

You can also use queues with synchronous requests, but you'll have to ensure that you always have enough workers to flow quickly.

Some examples of queues would be: Zeromq, RabbitMQ, IronMQ, SQS (AWS) ... There are many more, you have to see which fits your requirements better.

Some advantages of the queuing approach are:

  • Decoupling between modules
  • Easy to scale
  • Most of the queues have an http interface, which makes it simple to use in any language. (ZeroMQ being an exception because it is a library and not a program, but it has a wrapper for many languages so it gives the same).
  • Queues cushion the impact of request peaks.

As for the synchronous vs asynchronous part, I will go a little deeper to avoid doubts.

There are two levels to choose whether the call will be asynchronous or synchronous. First level is the client request to the server. Will the client wait for the response or will it do the request and go do other things while the server processes it? Second level is how the server will handle the very operation it should do when receiving a request. in the case of synchronous the server will be able to attend a request per process / thread. in the case of asynchronous the server is able to serve multiple requests per thread.

In case of the node because it is javascript and has only one thread that executes its code, the language forces you to use the server operations that require I / O asynchronously. It turned out that this model can meet more requests than the synchronous model + one request per thread.

When I asked whether the request was asynchronous or synchronous in your case, I was referring to the first option rather than the second. As you use node all your internal server operations using I / O will be asynchronous. What you should decide is whether your user will receive his response on time, with the response of the HTTP request he makes, or by following one of the 3 options:

  • Querying the server with pooling to know if the operation has already been completed.
  • Receiving a notification via websocket.
  • When refreshing the page.
10.03.2016 / 14:55