Server-Sent Events

Protocol

Overview

SSE (Server-Sent Events) is a one-way real-time technique where the server keeps pushing events to the client over a single persistent HTTP response stream.

You subscribe simply with the browser's `EventSource` API, and data flows in over an open response with the `text/event-stream` content type.

Details

The format is very simple: the server keeps the connection open and streams text lines like `data: ...\n\n`, extensible with `event:` (event name), `id:` (event ID), and `retry:` (reconnect interval). With no separate protocol upgrade, it runs over ordinary HTTP/HTTPS, so it's compatible with proxies, load balancers, and firewalls. A decisive advantage is automatic reconnection and resumption via `Last-Event-ID`: if the connection drops, `EventSource` reconnects itself and sends the last received ID to resume without gaps.

Choosing between SSE and WebSocket is the practical crux. SSE specializes in one-way, text server→client delivery, making it lightweight and robust for notifications, live dashboards, progress, and LLM token streaming where the server only needs to push. Conversely, if the client must send actively or you need binary data, WebSocket fits. Limitations: it's one-way, and under HTTP/1.1 the browser's per-origin connection limit (~6) means many SSE streams across tabs can exhaust connections (mitigated by HTTP/2 multiplexing). Unlike a webhook, which sends only when an event fires, SSE streams continuously over an open connection.

Related types