The Impact of Server-Sent Events

Phable
Phablecare
Published in
4 min readSep 2, 2022

In web development, there are various ways of showing the latest information to consumers. In this blog, we are going to see the impact of moving from one way to the other.

There are primarily three ways of extending information to clients:

  • Polling
  • Web sockets
  • Server-Sent Events (SSE)

Let’s go through these strategies with some real data.

Assume a new business provides some services on its platform. The number of clients today is 10 who avail the services using a mobile app. Also, assume that each client will handle 100 orders per day for this business. Let’s say the business boomed and the service is now popular amongst 100K clients within 3 months.

Polling

The most basic strategy is to poll data periodically from the server. However, the server may or may not have data. The strategy can be improved slightly by switching to long polling in which the server holds on to the request until it has the data.

For a system in it’s infancy stage, it might be a quick way to deliver business value. However, the toll it takes on the systems is grossly underestimated.

Let’s look at some numbers, considering a 10-second interval, a simple get order data API which might conservatively consume 10 bytes per call would explode from 1MB per day to 8GB with the number of clients growing from 10 to 100K.

Not to be missed is the number of API calls per day from a meagre 86K to almost a billion calls. The actual number of orders for which the client needed updates is 100. One API call would involve authorization as well, which takes an additional toll on the database or cache.

It is irrelevant how fast the backend system is or how optimized DB queries are. The sheer number of calls is alarming.

We can do better! Let the server say — I have updated data. Go ahead and update yourself.

Time to graduate to Web Sockets!

Web Sockets

Web sockets are the two-way full-duplex connection between a client and server. They are particularly useful when data needs to flow bidirectionally and are specifically useful in gaming. More can be read here.

Also, web sockets are a different protocol as compared to HTTP. Therefore, the effort to change the existing APIs is huge.

For the HealthPe use case, web sockets were not needed.

Enter Server-Sent Events.

Server-Sent Events (SSE)

SSE enables the server to send data, as and when it becomes available, to clients. More can be read here.

Let the numbers talk!

For the same setup, with 100K clients handling 100 orders each per day, they need to know about only those orders and maybe some other stuff. That means the number of total calls to API Server drops by close to 99%.

Let that sync in.

For a client population of 100K, we can reduce daily calls from almost a billion to 10 million. That bandwidth can be used to cater to more clients and more orders, leading to better revenues at a lower cost!

Impact

Lean application leads to smaller operational costs and more revenue. That is the direct economic impact on the top and bottom line.

The number of customers/clients in this analysis is capped at 100K. This number is nothing for a growing startup, especially in a market like India where volume is the king.

In technical terms, there is a direct impact on:

  • Data transfer to and from the server
  • API Server resources
  • Database IOPS
  • Volume metrics of the API server

Summary

Polling might be good for a minuscule customer base. Depending on the time it takes for the business to boom, engineering may not have time to catch up with the volume. To support a growing customer base, plan now to migrate to better communication — SSE or Web sockets.

The business impact is real and cannot be ignored.

Phable is an innovative lifestyle disease management app simplifying life for patients & doctors through health monitoring and doctor intervention.

Download Phable: Play Store (or) App Store

Words by: Upesh Jindal

--

--

Phable
Phablecare

Phable is a complete companion for those with lifestyle diseases. (https://phablecare.com/)