Issue #15 - Understanding Technologies Behind Real Time Data Fetching
Understand Polling, WebSocket, EventSource and Webhook to know how your favorite apps deliver real time updates
You receive real-time updates from applications constantly. Whether it's a chat application, the news feed on Facebook or Instagram, or live location tracking in a car-hailing service, delivering real-time updates has become more important than ever before. Chances are, all of these apps are using one of these technologies.
Polling
Polling is like repeatedly checking to see if something has changed, and it's used to keep systems updated with the latest data.
In terms of client-server request, the client asks the server "Do you have new information for me?”. The server responds, and the client repeats the question periodically to stay updated. There are mainly two kinds of polling-
Short Polling: The client regularly sends requests to the server at fixed intervals, asking if there are any updates.The server responds immediately, whether there is new information or not. It's a simple and commonly used method, but it can result in a higher volume of unnecessary requests.
Long Polling - The client sends a request to the server and it only returns response if any information is available or report a timeout, but no empty response unlike short polling. The client wait until it gets a response and then again sends a request. One of the downside of long polling is scalability. Maintaining open connections for each client can take up lot of server resources.
WebSocket
WebSockets allows information to flow back and forth between client and the server instantly, without the need for continuous asking or checking.
The client and the server establish a constant, two-way communication channel. Once the connection is open, either client or the server can send messages to the other at any time without waiting for a request. WebSockets offer advantages like lower latency and reduced overhead.
EventSource
Eventsource is similar to Websockets, but it is one-directional, only server can send data. It can only send text data, no binary data. It is much simpler and maybe applicable in projects where WebSocket is overkill. To receive data from server, we need to create new EventSource(url) in client side.
EvenSource makes sense when you need to only GET data from server. For example, live stock market data.
Webhook
Every time you purchase something with your card, most probably you always receive a SMS from your bank of your purchase history. That’s webhook in action.
Webhooks provide one system to communicate to another system when an event occurs.
When you make a purchase with your card, it triggers a purchase event in the bank's system.
The bank has set up a webhook endpoint to handle events related to purchases. This webhook endpoint is essentially a URL provided by the SMS service or an internal system responsible for sending SMS notifications.
The purchase event triggers the webhook, which, in turn, instructs the SMS service to send you a notification.
That’s it. Thanks for reading!
Very Informative!