Friday 24 April 2020

So what's the easiest best solution for deploying NodeJS app with socket.io and cronjobs to multiple servers?

I don't know if the title is the best way to ask the question and I can see how it can be a little confusing, but what I'm asking is that:I have a NodeJS app that uses socket.io to communicate with some clients and the clients being able to communicate with one another (through the server of course) and I want to deploy my NodeJS app to multiple servers to do a load balancing but keep the sockets working no matter the server that handles the request...In addition to that I have multiple cronjobs (cronjobs are dynamic, I have a cronjob for each user and on server start I start iterating through the users that need a cronjob running and start running it for them, also users can make a POST call to my public API with their token and start / destroy their cronjob...) the cronjobs are running every second and checking if there's data (belong to their user) in a certain table in MySQL DB and if there's then it transform it in a certain way and put it in a new table and removes the old row from the previous table, and I want to make sure the if I do a load balancing then my servers are not gonna both perform the same cronjobs twice or even more times for each user, which will make it create duplicate content in my DB..I'm using the cronjob npm for the cronjob operation...I'd love to get a link to a tutorial or an article that covers how to deploy my NodeJS app to NGINX or something for someone who has never done load balancing for their NodeJS apps, all while keeping the socket.io working and preventing certain cronjobs from running multiple times..

Submitted April 24, 2020 at 08:07PM by s_trader

No comments:

Post a Comment