Server-Sent Events
A standard way for a server to keep an HTTP response open and push a stream of text events to the client, in one direction only.
In more detail
Each event is a few text fields, such as id, event and data, ended by a blank line, sent as text/event-stream. Browsers reconnect automatically and send the last event identifier so the server can resume. Use a WebSocket instead when the client must also send messages continuously.
Examples
In the browser: The browser's EventSource object reconnects automatically and delivers each event to your code.id: 5
event: tick
data: {"val":42}
data: {"token":"Hello"}
Related terms
- Last-Event-ID — The header a Server-Sent Events client sends when reconnecting, carrying the id of the last event it received so the server can continue from there.
- retry hint — The retry field in a Server-Sent Events stream, which tells the client how many milliseconds to wait before reconnecting after a break.
- WebSocket — A protocol that turns an HTTP connection into a long-lived, two-way channel where client and server can each send messages at any time.
- streaming — Sending a response in pieces as they become available instead of building the whole thing first.
- ReadableStream — A browser object that delivers data in chunks as it arrives, such as a fetch response.body, instead of all at once at the end.
- EventSource — The Argo Events resource that listens to an outside source, such as a webhook or a queue, and publishes what arrives as events.
- heartbeat — A small message sent at regular intervals on a long-lived connection to prove that both ends and the path between them are still alive.
- Content-Type — The header that states what format a message body is in, such as application/json.
- polling — Having the client ask repeatedly, on its own schedule, whether something has changed or finished.
Taught in
- What An AI Engineer Does — AI Engineering: LLM Apps, RAG & Agents
- Streaming Responses — AI Engineering: LLM Apps, RAG & Agents
- What MCP Is — AI Engineering: LLM Apps, RAG & Agents
- Remote Servers And Trust — AI Engineering: LLM Apps, RAG & Agents
- Server-Sent Events — Modern API Architecture: REST, GraphQL & gRPC
- The Fetch API: Streaming Responses, HTTP Caching And Keepalive — Frontend Architecture & Web Platform
- Server-Sent Events: Streaming Updates & Recovery — Production Full-Stack Engineering
- Bidirectional WebSockets: Reconnection & Heartbeats — Production Full-Stack Engineering
- Route Handlers: RESTful Endpoints with NextRequest — Next.js 15 & Modern App Router Architecture
- Streaming Endpoints: Server-Sent Events & NDJSON Feeds — Next.js 15 & Modern App Router Architecture
- Native WebSockets: Bidirectional Real-Time Streams — Node.js Internals & Backend Services