Server Sent Events (SSE)

๐Ÿšจ ๐—ง๐—ต๐—ฒ ๐—ฝ๐—ฟ๐—ผ๐—ฏ๐—น๐—ฒ๐—บ

Your web app needs real-time updates like stock prices, chat messages, and live scores, but you only need data flowing one direction - from server to client. WebSockets are bidirectional and more complex than needed, while polling wastes bandwidth with constant "anything new?" requests.

๐Ÿ’ก ๐—ช๐—ต๐—ฎ๐˜ ๐—ถ๐˜€ ๐—ฆ๐—ฆ๐—˜?

A simple HTTP-based protocol where the server keeps a connection open and pushes text data to the client whenever it wants. Think of it as a one-way WebSocket that's built on standard HTTP.

โš™๏ธ ๐—›๐—ผ๐˜„ ๐—ถ๐˜ ๐˜„๐—ผ๐—ฟ๐—ธ๐˜€?

Client opens connection: new EventSource('/events')

Server responds with Content-Type: text/event-stream and keeps connection alive

Server pushes data in simple format:

data: {"price" : 142.50, "symbol" : "AAPL"}
data: {"price" : 143.10, "symbol" : "AAPL"}

Client receives events via

eventSource.onmessage = (event) => { ... }

๐Ÿ‘ ๐—š๐—ฟ๐—ฒ๐—ฎ๐˜ ๐—ณ๐—ถ๐˜ ๐—ณ๐—ผ๐—ฟ

  • Live dashboards (metrics, analytics updates)
  • News feeds and social media timelines (10 new posts since you loaded the page)
  • Stock tickers and financial data
  • Server-sent notifications
  • Live sports scores or election results
  • Progress updates for long-running tasks

โš ๏ธ ๐—ช๐—ต๐—ฒ๐—ป ๐˜๐—ผ ๐—ฎ๐˜ƒ๐—ผ๐—ถ๐—ฑ

  • If you need bidirectional communication (client sending frequent messages back)
  • If you need Binary data (SSE is text-only)
  • When you have very high-frequency updates (hundreds per second)
  • If you need guaranteed delivery (SSE doesn't have acknowledgments)

๐ŸŽฏ ๐—ฃ๐—ฒ๐—ฟ๐—ณ๐—ฒ๐—ฐ๐˜ ๐—ณ๐—ผ๐—ฟ ๐—ถ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„๐˜€

Mention SSE when designing notification systems, real-time dashboards, or any "server pushes updates to many clients" scenario. Great middle ground between simple polling and complex WebSocket infrastructure.