Defining the requirements of real time
There are two techniques available for publishing real-time data on the web:
- Pull technique: This is where the client raises a request to get the latest version of data. HTTP polling and HTTP long polling are two examples of implementations of this pull technique.
- Push technique: This is where the server pushes updates to the client. WebSockets and server-sent events are two implementations of this push technique.
We are not going to discuss or compare these techniques in detail, as it is not the goal of this chapter; however, in general, push techniques have a lower latency compared to pull ones. For this reason, we will use the push technique and WebSocket as the implementation for our requirements.
In short, the WebSocket protocol is a stateful communication protocol that establishes a low-latency bi-directional communication channel between a client and a server. In this way, messages can be sent back and forth between...