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.