Tuesday 25 July 2017

Best practices for app with web and worker processes, and communicating background job results to client via socket.io?

I have a question about the best practice structure when dealing with a web server, background worker job queues, and needing to push job results to connected clients via websockets using socket.io.Normally I have the following setup: Web server receives request, responds to client quickly, then starts a new background job on a worker queue. On the worker side of things some work is done and saved to the database, maybe an email is sent out, etc. However, for the first time I now need to communicate the job results back to the client using socket.io.So my question is how to properly push job results to the client? Should the worker be able to use something like socket.io to communicate back to the client? Is this even possible if the client is connected via socket.io to the web server, but the background worker is on a completely different machine? I guess an alternative would be the worker could queue up a "results" job itself that the web server listens for, and then the web server would be the one sending the socket.io message back to the client, but I'm just not sure how practical this is or what the best way to do this is.I don't have a ton of experience with websockets or scaling large apps so curious how to structure all of this. Appreciate the help thanks!

Submitted July 25, 2017 at 09:15PM by m9js

No comments:

Post a Comment