๐Ÿ“จ

SSE (Server-Sent Events)

Serverโ†’Client Unidirectional Stream

SSE is an HTTP-based unidirectional streaming technology. The server can continuously send events to the client, but client-to-server communication requires separate HTTP requests. It is simpler than WebSocket, compatible with HTTP/2, and has automatic reconnection built into browsers.

Architecture Diagram

๐ŸŒ
Client
EventSource API
โ‘  GET Request
HTTP Keep-Alive
โ‘ก text/event-stream
data: {...}
data: {...}
Unidirectional stream (Server → Client)
๐Ÿ–ฅ๏ธ
Server
Content-Type: text/event-stream
On disconnect, the browser auto-reconnects (Last-Event-ID sent)
Flow Description
  1. Client sends HTTP GET request to server via EventSource API
  2. Server responds with text/event-stream, keeps connection
  3. Server streams events in data: format
  4. Browser auto-reconnects on disconnect

How It Works

1

Client sends HTTP GET request to server via EventSource API

2

Server responds with Content-Type: text/event-stream, maintaining connection

3

Server streams in data: format when events occur

4

Browser auto-reconnects on disconnect (using Last-Event-ID)

Pros

  • Simple implementation based on HTTP
  • Built-in automatic reconnection
  • Leverages HTTP/2 multiplexing
  • Text-based, easy to debug

Cons

  • Unidirectional only (serverโ†’client)
  • Inefficient for binary data transfer
  • Not supported in IE/older browsers
  • Max concurrent connection limit (6 in HTTP/1.1)

Use Cases

Real-time notifications/feeds AI chatbot streaming responses (ChatGPT) Stock price updates Build/deploy log streaming Live scoreboards