India-Pakistan standing against each other once again for the Asia cup. Luckily the match was on weekends so we got to sit at home and watch. But many times the match is going on and we are working – in such case people prefer opening a site showing live updates of the match.
Real time updates is a very common use case considering evolution of the products in the modern era. And WebSocket is probably the most popular tool used for achieving great results when it comes to updating information as soon as it is available.
Obviously WebSocket is not the only technique available. Similar results can be achieved using polling or comet techniques. But these techniques always have a limitation of being unidirectional where client sends a request and server provides the response.
WebSockets allows full duplex channel of communication between client and server. This allows dedicated connection to be established between client and server avoiding overheads of creating a new connection with every request. This in turn has enhanced the way applications are designed are more elegant in showing updates in real time.
Very common use cases where WebSockets add value are Chat applications, Scoreboards of Sports events, Stock Market applications and of course gaming applications. Recommendation is to use WebSockets only when continuous data updates are needed in the application. In most common scenarios that might not be needed and basic http model will work.
As opposed to http requests which are stateless by definition, WebSockets are dedicated connections between two ends – hence is not stateless. Which might pose a challenge in case of horizontal scalability. Additional techniques have to be implemented in combination with WebSockets to achieve high levels of scalability with the implementations.
Do you feel your application or product requires real time updates with WebSockets?