Building Scalable Facebook-like Notification using Server-Sent Events and Redis

Amr Saleh
Javarevisited
Published in
4 min readJul 3, 2020

--

Photo by Cristian Dina from Pexels

Sometimes we want the server to notify the client on changes. This is something that is not possible in traditional HTTP web applications. In traditional web applications, the client has to establish a connection with the server and then waits for the response from the server. This is the problem that server-sent event is solving. The Idea behind server-sent event (SEE) is the client subscribes to stream of updates generated by the server and, a notification is sent to the client, whenever a new event occurs.

Before we go deep into SEE, let’s first understand the other possible solutions and their limitations:

Polling is a technique where the client repeatedly polls the server for data, if there are no updates from the server, an empty response is returned. The limitation of polling is extra polling creates a greater HTTP overhead.

Long polling is a variation on polling. In long polling, if there is no updates, the server holds the connection open until new update becomes available. When new data becomes available, the server responds, closes the connection, and the process repeats. The limitation is the implementation of this technique requires hacks such as appending script tags to an ‘infinite’ iframe.

--

--

Amr Saleh
Javarevisited

I’m a software engineer who is passionate about software architecture and design. Enjoy coding in Java, Scala, and JavaScript.