What is the difference between long-polling, websockets, and server-sent events?
Answers
Explanation:
Building a real-time web application is a bit challenging one, where we need to consider how we are going to send our data from the server to the client. Technologies that enable this “proactively” have been around for quite some time and are limited to two general approaches: client pull or server push.
A few ways to implement these:
Long/short polling (client pull)
WebSockets (server push)
Server-Sent Events (server push)
Client pull — client asking server for updates at certain regular intervals
Server push — server is proactively pushing updates to the client (reverse of client pull)
High level comparison of Short/Long polling and SSE
Let’s take a simple use case to compare the above technologies and choose the right one.
Example :
Our example use case is very simple. We need to develop a dashboard web app that streams list of activities from websites like (GitHub/Twitter/..etc). The purpose of this app is to choose the right one among the various methods listed previously.