Skip to main content

Server-Sent Events

Server-Sent Events push a one-way stream of text updates from server to client over a single long-lived HTTP connection, with auto-reconnect.

Server-Sent Events (SSE) is a standard that allows a server to send a stream of updates to a browser or client over a single, long-lived HTTP connection. Communication flows in one direction only, from server to client.

How It Works

The client opens a connection to an endpoint, typically using the browser's EventSource API, and the server responds with the content type text/event-stream and keeps the connection open. The server then writes events as plain text, each consisting of fields like data, event, and id, separated by blank lines. The client receives these events as they arrive.

SSE includes built-in conveniences. The browser automatically reconnects if the connection drops, and the last event id lets the server resume the stream from where it left off. Because SSE rides on ordinary HTTP, it works through most proxies and firewalls without special handling.

Why It Matters

Many real-time features only need the server to push updates: notifications, live scores, progress indicators, and streaming AI model output token by token. For these cases SSE is simpler than WebSocket. It uses a familiar protocol, needs no special server upgrade handshake, and gives reconnection for free.

The limits follow from its one-way nature. The client cannot send messages back on the same channel, so interactive use still requires WebSocket. SSE also carries only text, and older HTTP/1.1 connection limits per domain can constrain how many streams a page opens, which HTTP/2 multiplexing relieves.

Related Terms

Server-Sent Events is a simpler, one-way alternative to WebSocket, benefits from HTTP/2 multiplexing, and complements webhooks for delivering updates.