dlopezgonzalez
dlopezgonzalez

Reputation: 4297

Approaches to build a nodejs backend, use one or several instances?

I am planning to build a nodejs application as back end of a web application.

This server application will provide a rest api, websockets service and process to scrape some sites with a headless navigation (like zombie.js) each n hours to feed a database.

I would to ask if it's a good approache build all the things in one nodejs instance or if it's better use several nodejs applications for every task.

Upvotes: 0

Views: 91

Answers (2)

Dmytro Medvid
Dmytro Medvid

Reputation: 5238

In my opinion better way is using different Node.js applications. First one will server your API. Another one will work as a socket server on different port.

About scraper it can be PHP (as well as nodejs) script which will run as a cron job. How to setup cron job you can check this question: https://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job

or this tutorial for Ubuntu server: https://help.ubuntu.com/community/CronHowto

I think it will be best approach.

Upvotes: -1

Hiren S.
Hiren S.

Reputation: 2832

If you are having small size application (which doesnot require scale in future), you can keep all the stuff Rest, Socket, scraping on the same project).

Note: After scraping if you are processing HTML content, it will take some time to process that in Sync manner. So at that time event loop will be blocked. So Rest API will not handle any request. In this scenario, you can keep Rest and Socket combinely in one project and Scraping thing in another project.

If you are planning to scale in near future, I suggest to Keep Seperate Instance, considering Benefit of SOA in scaling.

Upvotes: 2

Related Questions