Most of the communication on the Internet comes directly from the clients to the servers. The client usually sends a request, and the server responds to that request. It is known as a client-server model, and it works well in most cases. However, there are some scenarios in which the server needs to send a message to the client without the preceding request.

In such cases, we have a couple of options: we can use short and long polling, webhooks, websockets, or event streaming platforms like Kafka. However, there is another technology, not popularized enough, which in many cases, is just perfect for the job. This technology is the Server-Sent Events (SSE) standard.

What Are Server-Sent Events?

SSE definition states that it is an HTTP standard that allows a web application to handle a unidirectional event stream and receive updates whenever the server emits data. In simple terms, it is a mechanism for unidirectional event streaming.

Browsers Support

It is currently supported by all major browsers except Internet Explorer.

Message Format

The events are just a stream of UTF-8 encoded text data in a format defined by the Specification. The important aspect here is that the format defines the fields that the SSE message should have, but it does not mandate a specific type for the payload, leaving the freedom of choice to the users.

{

 "id": "message id <optional>",

 "event": "event type <optional>",

 "data": "event data –plain text, JSON, XML… <mandatory>"

}

#cloud #tutorial #cloud native #react native

How to Build Real-Time Notification Service Using Server-Sent Events (SSE)
4.55 GEEK