Problem
Clients need live updates such as notifications or progress, but polling wastes requests and adds delay. Full duplex channels are heavier than needed when the client never sends data on the stream.
Also known as: sse, eventsource
Stream one-way server-to-client updates over a long-lived HTTP response.
Clients need live updates such as notifications or progress, but polling wastes requests and adds delay. Full duplex channels are heavier than needed when the client never sends data on the stream.
Server-Sent Events (SSE) is a standard way for a server to push a stream of text events to a browser over a single HTTP connection. It is simpler than WebSockets and fits any feed where data flows only from server to client.
The server responds with content type text/event-stream and never completes the response. Events are separated by blank lines.
GET /stream HTTP/1.1
Accept: text/event-stream
id: 105
event: price
data: {"sym":"ACME","px":41.2}
: heartbeat
In the browser, new EventSource("/stream") opens the connection and fires handlers per event name. If the connection drops, EventSource reconnects after a delay and sends the Last-Event-ID header. The server uses that id to replay events from a short buffer or log. Heartbeat comments every 15 to 30 seconds prevent idle timeouts at load balancers.
Low - no special infrastructure
Medium - connection capacity and buffering proxies
Low - small protocol
Proxy buffering delays or swallows events
Lost events on reconnect without id-based replay
Connection storms after a server restart