11

We have a web application that currently uses polling to handle continuous updates.

While switching to long polling may be a small bandaid to the issue, we wanted to implement a Websockets solution that will be durable and scalable.

My question is: what kind of architecture will be needed for this?

I have done some research myself and have found that the typical setup for an enterprise application is something like this: websocket flow

The execution flow of a connection then would be something like this:

  1. Initial handshake
    • Client makes an HTTP Request to Server along with JS to request a Websocket connection
    • Server responds, Header contains the Upgrade directive and switches protocols for that client
    • Websocket Server establishes a Websocket connection with client
  2. Client submits a POST/PUT/etc.
    • Webserver (Apache/Nginx) fetches result from query
    • Webserver sends result to the MQ where it is added to the queue
    • Message is sent to Websocket server from MQ
    • Message is sent back to the client

Is this approach correct? Am I missing anything? Am I understanding something incorrectly?

3
  • Symfony2 is not the best idea i think, anyway I understand that you want create Websocket connection inside symfony controller, correct ? Commented Jun 9, 2016 at 12:37
  • Why do you need MessageQueue between nginx and nodejs? Nodejs excells at handling multiple requests... Also there is no need for HAPROXY, because nginx can handle protocol upgrade by himself. Do you want to have it so complicated? I had similar solution with almost identical setup and it was very hard to maintain it. Keep in mind that most of a time you need a mechanism to pass session data from nginx (PHP) to nodejs ... Commented Jun 13, 2016 at 8:05
  • @MitjaGustin The Message Queue would be a larger part of the application and used for more than just the websockets. In that sense, I am looking for a websocket solution that will work with a Message Queue. HAProxy, on the other hand, is not a hard requirement - it may be replaced by another kind of Load Balancer and is inconsequential. I was merely trying to get a rough idea of the architecture in such a case. Commented Jun 13, 2016 at 9:02

2 Answers 2

4
+50

Try having a look at this: socketo.me

Kinda gives you an idea. From what I can see, this is fairly similar to what you've envisioned in the architecture diagram you posted.

May also be worth looking at this Stackoverflow question's answer.

Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried GOS WebSocketBundle ? I'have used it on production site to handle chat and along with stunnel it works flawlessly over SSL.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.