<strong>Server-Sent Events (SSE)</strong> is a technology that allows servers to push updates to clients over a single HTTP connection. It's simpler than WebSockets and perfect for one-way real-time updates.
The News Ticker Analogy
SSE is like a news ticker on TVβthe station continuously sends updates, and your TV displays them. You don't send anything back; you just receive.
TV Screen (Client)
Displays updates
News Feed (SSE)
Continuous stream
News Station (Server)
Sends updates
Opens Connection
Server Pushes Data
Sends Events
Client opens connection
const eventSource = new EventSource('/api/updates')
Server keeps connection open
HTTP connection stays alive
Server sends events
data: {"message": "New update"}\n\n
Client receives events
eventSource.onmessage = (event) => { ... }
Auto-reconnect on disconnect
Browser automatically reconnects if connection drops
Wrong
"SSE and WebSockets are the same"
Correct
<strong>SSE is simpler, one-way only</strong>. WebSockets are bidirectional but more complex. Use SSE for server-to-client updates (notifications, live feeds). Use WebSockets for chat.
Live stock price updates:
Client opens SSE connection to /api/stock-prices
Server pushes price updates every second
Client displays live prices without polling
Connection automatically reconnects if network drops