Server Sent Events (SSE)

🚨 The problem

Your web app needs real-time updates like stock prices, chat messages, live scores, driver updates, ticker changes, or notifications 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.

💡 What is SSE?

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.

⚙️ How it works?

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" : 152.50, "symbol" : "AAPL"}
data: {"price" : 153.10, "symbol" : "AAPL"}

Client receives events via

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

👍 Great Fit For

  • 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

⚠️ When to Avoid

  • 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)

🎯 Perfect For

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.