1

I'm engineering architecture of a new web based software.

I've never worked on high-scale softwares before and I'm reading a lot about it.

To increase client-side speed and reduce load on servers, and also enabling server-to-client communication, I decided to use WebSockets.

To process request from clients, I always read, hear and watch here and there that I need to push requests from WebSocket to a message queue and then pop those messages to a worker, then process data and push results to message queue again, then pop to the WebSocket server then finally send the result back to the client. Here is a simple schematic that what they say:

Client -> WebSocket -> Message Queue -> Worker Process -> Message Queue -> WebSocket -> Client

But when I think of this architecture, Message Queue seems an unneeded. Actually I believe that in this architecture, WebSocket can be a message queue itself. It gets messages from client, then sends them to another place. All we need to do is register worker processes in WebSocket server as a Worker, then when a messages receives from client, directly send the message to an idle worker, and if there is no idle worker available, keep the message in a FIFO queue and when a worker becomes available, send oldest message to that worker. This way, we get rid of message queue server. Here is a simple schematic that what I mean:

Client -> WebSocket -> Worker Process -> WebSocket -> Client

So here is my questions:

  1. Why why everybody says we need a message queue server?
  2. What can be the downside of removing message queue server and implementing queue inside the WebSocket server?
5
  • I think it's worth pointing out that the WebSocket API specification does not include any mention of message queues at all, and all of the client libraries which implement WebSockets appear to be usable as-is without message queues: developer.mozilla.org/en-US/docs/Web/API/WebSockets_API Sep 20, 2022 at 6:20
  • @BenCottrell, My question is about pros/cons of implementing message queue inside WebSocket Server instead of using a 3rd message queues, considering high-scalability.
    – vusra
    Sep 20, 2022 at 6:38
  • 1
    "Why why everybody says we need a message queue server?" -- where are you getting this from? I've never heard someone say this. Sep 20, 2022 at 13:20
  • 1
    @vusra Writing your own middleware is a fairly large and complex undertaking; so it really depends why you would want to implement it from scratch. If other people have already invested a lot of effort doing all the heavy lifting; most of the time you're unlikely to need to tread that old ground again and reinvent the wheel with middleware from the ground upward, usually you can just grab something which already works and pass messages to it. See: softwareengineering.stackexchange.com/questions/29513/… Sep 20, 2022 at 14:57
  • @BenCottrell I've read your comment and all the answers in the link and it helped to make final decision. Thank you.
    – vusra
    Sep 20, 2022 at 20:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.