HTTP Push Technologies in just 5 minutes!

Typically, when we talk about HTTP requests, it is always about clients talking to servers, 

but can a server talk to the client?

Yes, it is possible!


How you ask? 

Well, the magic words are - "HTTP Push Technologies"





Below are 4 different HTTP push technologies:

1. Web Sockets

  • Web Socket connection is preferred when we need a persistent bi-directional low latency data flow from the client to the server and back.
  • Typical use-cases of web sockets are messaging, chat applications, real-time social streams, browser-based massive multiplayer games, etc. These are apps with quite a significant number of read-writes compared to a regular web app.
  • With web sockets, we can keep the client-server connection open as long as we want.
  • Have bi-directional data? Blindly go ahead with web sockets.
  • Also, note that web sockets don’t work over HTTP. The mechanism runs over TCP. Also, the server and the client should both support web sockets. Else it won’t work.

2. AJAX Long Polling

  • Long polling lies somewhere between AJAX and Web Sockets.
  • This technique is similar to normal HTTP requests. In this technique, instead of immediately returning the response, the server holds the response until it finds an update to be sent to the client.
  • The connection in long polling stays open a bit longer compared to polling. The server doesn’t return any response. If the connection breaks, the client has to re-establish the connection to the server.
  • The upside of using this technique is that fewer requests are sent from the client to the server than the regular polling mechanism. This cuts down a lot of network bandwidth consumption.
  • Long polling can be used in simple asynchronous data fetch use cases when you do not want to poll the server every now and then.

3. HTML5 Event Source API and Server-Sent Events

  • The Server-Sent Events (SSE) implementation takes a different approach. Instead of the client polling for data, the server automatically pushes the data to the client whenever the updates are available. The incoming messages from the server are treated as events.
  • Via this approach, the servers can initiate data transmission toward the client once the client has established the connection with an initial request.
  • This helps eliminate a considerable number of blank request-response cycles cutting down the bandwidth consumption by notches.
  • To implement the server-sent events, the backend language should support the technology. On the UIHTML5 Event-Source API is used to receive the incoming data from the backend.
  • An important thing to note here is that once the client establishes a connection with the server, the data flow is in one direction only, from the server to the client.
  • SSE is ideal for scenarios like a real-time Twitter feed, displaying stock quotes on the UI, real-time notifications, etc.

4. Streaming over HTTP

  • Streaming over HTTP is ideal for cases where we need to stream extensive data over HTTP by breaking it into smaller chunks. This is made possible with HTML5 and a JavaScript Stream API.
  • The technique is primarily used for streaming multimedia content, like large images, videos, etc., over HTTP. Empowered by this technique, we can watch a partially downloaded video as it downloads by playing the downloaded chunks on the client.

Let's stay in touch for more insights and updates. You can find me on my LinkedIn Profile. Looking forward to connecting!