Skip to content

Server-sent events

Server-sent events carry text notifications from server to client over HTTP, for example about the progress of a background job.

Also known asSSE
APIs and data contracts

Server-sent events, or SSE, carry text notifications from server to client over an HTTP connection. In the browser, EventSource provides the interface; the event stream uses text/event-stream. The connection is one-way. Commands from client to server need a separate route, such as ordinary HTTP requests.

A notification about a running report job

A fictional portal receives this event block:

id: evt-12
event: job-status
data: {"jobId":"J-52","status":"running"}

The blank line ends the block. Event identifier, event type and payload have different roles. Here the server reports that creation is running; the notification does not mean the file is ready. The field values are our own example.

After a recoverable interruption, EventSource can reconnect automatically. A previously set, non-empty event identifier is reported through Last-Event-ID. The server must decide whether and how it provides missing notifications again. The identifier does not create a stored event history.

The application therefore needs to handle duplicate notifications and history that is no longer available, for example by fetching the current job state again. SSE does not guarantee that a business action is performed exactly once. Access to the project and job must also be checked when connecting and when delivering notifications.

Sources

Articles on this topic

Your project with ASES

Describe your project to us. We will get back to you with an initial assessment.