Do you want to developing once can be used by many another places? Do you want your function can be supported either by android,IOS or desktop?
At the begin of design, you need to consider those things. The first thing you may figure out is using html5 to developing.
It a good new that WebSocket standard is supported by html5 and also supported by so many main aspect Browsers broad.
For a kind of broadcast requirement we can use some client plugins to effectively communicate with servers. For some light level functions like comment we need to add too heavy plugins to ours' application. So WebSocket is a better solution for us.
The simplest design
One javascript WebSocket client plugin in browser and a WebSocket server technology like Spring. In Spring you can create a controller to receive the message and send message to Browser. But this is a hello world level design. It just only to use to study the WebSocket skill or do some very simple applications.
A better solution that can be shared
For server-side, we can design a independent layer that just only too use to connect client and transfer message. This layer does not need to implement some business requirement. So this layer can be reused by many kinds of business requirement at the same time, it's a realtime communication layer that service the same situation for many difference business requirement.
1, When starts a Browser that sends a request to WebSocket Server and then connects to the WebSocket Server, this connection isn't close before the Browser is closed.
2,Sends a business request to the Business Server, If the user isn't login in will be redirected to login in login page, otherwise the request go to the server, the server will record the user's information or retrieve the user's information from database that it's recorded in after the user complete register. This user will send this piece of request message to a Message Queue server, The WebSocket Server have subscribed this Message Queue's Topic, As soon as the Message Queue Server receive this kind of message the WebSocket Server will receive the message. Then the WebSocket Server sends this message to all of client or special client which is connecting.
Let start a really business requirement
We need to implement a comment and chat function. The login user can comment something to a article. All of user can communicate each other in real time. This function consists two blocks, one is font page that is for general user, the other is backend management system, manager of this system can reply to some special users from backend page.
Implement
1,We need to design a database table that record register users or chat users, the table have a column that stores a communication room number or communication topic.
2,Browser client sends a request with some parameters that include user's name and communication room or communication topic to business server.
3, Retrieve a token from business server. The token is used to verify in WebSocket Server. This token need have some business information that can be recognized by WebSocket Server.
3,Browser client sends a another request to WebSocket Server take along that token.Making a long connection with WebSocket Server.
4,Browser client invoke Business Server Interface for send chat message and at the same time the request with communication room or communication topic.
5,The Business Server find user list from database according to communication room or communication topic.
6,The Business Server constructs Queue Message and then send the message to Message Queue Server.
7,WebSocket Server send the message that have subscribed from Message Queue Server to receive user list that also from Message Queue Server.
Implement of Backend Server just need to retrieve from receiving users and construct message and then send to Message Queue Server, and the other parts is the same.