Back to all terms
ClientAPIrequestresponse
APIintermediate

Server-Sent Events (SSE)

A unidirectional HTTP streaming protocol where the server pushes real-time text-based events to the client over a persistent connection.

Also known as: SSE, EventSource, Event Stream

Description

Server-Sent Events (SSE) is a browser-native technology for streaming real-time updates from server to client over a standard HTTP connection. Unlike WebSockets, SSE is unidirectional (server to client only), uses regular HTTP (simplifying infrastructure -- no special proxy configuration needed), and includes built-in reconnection with automatic retry and last-event-ID tracking. The EventSource browser API makes consuming SSE streams trivial: const es = new EventSource('/api/events') with onmessage callbacks.

The SSE protocol uses a simple text-based format with event, data, id, and retry fields. Each event is separated by a double newline. Named events (event: orderUpdate) allow multiplexing different event types on a single connection, and the id field enables resumable streams -- on reconnection, the browser sends the Last-Event-ID header and the server can replay missed events. The retry field controls the reconnection interval in milliseconds.

SSE is ideal for use cases like live dashboards, notification feeds, progress updates for long-running operations, and AI/LLM streaming responses. It's simpler than WebSockets when bidirectional communication isn't needed and works through HTTP/2 with connection multiplexing. Limitations include a maximum of 6 concurrent connections per domain in HTTP/1.1 (resolved by HTTP/2), text-only data (binary requires base64 encoding), and no built-in client-to-server channel (use regular HTTP requests for that direction).

Prompt Snippet

Implement SSE endpoints using the text/event-stream content type with chunked transfer encoding. Structure events as: event: invoice.updated\nid: evt_123\ndata: {json}\n\n. Track last-event-id per client connection and replay missed events from an append-only event log on reconnection using the Last-Event-ID header. Set retry: 3000 to configure client reconnection interval. For Node.js, use res.write() with res.flushHeaders() and disable response buffering in NGINX (proxy_buffering off; X-Accel-Buffering: no). Implement heartbeat comments (: keepalive\n\n) every 30 seconds to prevent proxy timeouts.

Tags

ssereal-timestreamingeventshttp