Background processes in Node.js

前端 未结 6 1557
刺人心
刺人心 2020-12-22 16:48

What is a good aproach to handle background processes in a NodeJS application?

Scenario: After a user posts something to an app I want to crunch th

6条回答
  •  無奈伤痛
    2020-12-22 17:30

    Background jobs are not directly related to your web service work, so they should not be in the same process. As you scale up, the memory usage of the background jobs will impact the web service performance. But you can put them in the same code repository if you want, whatever makes more sense.

    One good choice for messaging between the two processes would be redis, if dropping a message every now and then is OK. If you want "no message left behind" you'll need a more heavyweight broker like Rabbit. Your web service process can publish and your background job process can subscribe.

    It is not necessary for the two processes to be co-hosted, they can be on separate VMs, Docker containers, whatever you use. This allows you to scale out without much trouble.

提交回复
热议问题