Reputation: 6520
I have a few Node.js API applications. They all follow a very similar model.
There is one HTTP server (express) which listens to requests, and queues insert requests.
There is another event handler which listens to this queue (it is currently in mongodb, but it could be redis or anything else), and processes items if found, and tries again after a fixed time interval.
Since my servers are all multi-core instances, I have forked child processes to distribute the load. But currently, each of these processes have both these event handlers (HTTP, and the queue handler).
Which is a better approach? Separating the handlers into different processes, or having both handlers in each process (my current set up)? Roughly 90% of my API calls result in adding an item to the queue, which will need to be processed by the queue handler later.
I initially had seperated both these into two different node applications itself, but I combined them into one to make process and application management on the server end easier.
Upvotes: 0
Views: 747
Reputation: 34337
Take a look at the 12-factor app, which recommends running separate applications for different independent tasks. However, I recommend hosting all tasks in the same code repository, to make it easier to do end-to-end testing and keep them in sync. Then, use a technique like Procfiles to launch multiple instances of different applications.
Upvotes: 1