Using Node.js servers, I wonder if it is possible and recommended to send an HTTP response from a delegated workflow instead of the main process. These workflows can be the Node.js servers themselves, or simply Node.js child processes that communicate via IPC.
I donβt think that the main cluster module https://nodejs.org/api/cluster.html can do what I want to do, because in this model all workers listen on the same port and they process all requests on behalf of the main process. I am looking for one core Node.js process that responds to all HTTP requests, it can authenticate and handle some requests, but it is also able to delegate intensive requests with heavy use or processor to the work pool.
Imagine that we have a GET request for a large amount of data, say, 2-3 MB.
We have at least 3 possible scenarios:
- The main process receives the request, queries the database for a large amount of data, and then sends the data back to the requestor.
- The main process receives the request, sends some data to the workflow using IPC, the worker receives data from the database, performs some heavy operations, and then the worker uses IPC to send all three MB of data back to the main process, which then sends the response.
- The main process receives the request, sends as little information as possible about the request flow to the worker, the worker does all the work, and the worker sends an HTTP response.
I am particularly curious about what makes No. 3 possible.
The following is a simple description of scenario 3:

(To be clear, I do not want to receive 3 responses in one request, I'm just trying to show that an employee can send a response on behalf of the main process).
Does anyone know how this can work with Node.js? How can this work in other languages? Usually I have no problems with the Node.js concurrency model, but with some data types, using the Cluster module is probably not the best way to achieve the highest levels of concurrency.
I believe that one term for this model is "direct response", that is, the worker responds directly to the request. And perhaps for this you can simply use the main cluster module https://nodejs.org/api/cluster.html .
source share