Photo by Scott Rodgerson on Unsplash
Server-Sent Events: The Overlooked Push Protocol
When developers need real-time server-to-client communication, WebSockets usually dominate the conversation. But Server-Sent Events (SSE) deserves more attention. This simpler, unidirectional protocol handles many real-time use cases with less complexity and better operational characteristics than its bidirectional cousin.
How SSE Works
Server-Sent Events operates over standard HTTP. The client opens a long-lived GET request, and the server keeps the connection open, streaming data as text events whenever something needs to be pushed. Each event follows a simple format: field-value pairs separated by newlines, with a blank line marking the event boundary.
The browser’s EventSource API automatically handles connection management, including exponential backoff reconnection when connections drop. The server just writes to the response stream. No handshake upgrade, no frame parsing, no binary protocol negotiation.
This simplicity extends to infrastructure. SSE flows through standard HTTP/1.1 or HTTP/2 connections. Proxies, load balancers, and CDNs that handle HTTP generally handle SSE without special configuration. The protocol rides existing connection multiplexing in HTTP/2, so multiple SSE streams share a single TCP connection without the head-of-line blocking that plagued HTTP/1.1.
When Unidirectional Wins
Many real-time scenarios only need server-to-client push. Live dashboards, notification feeds, stock tickers, log streaming, and progress updates all follow this pattern. The client displays information as it arrives but sends commands through separate HTTP requests.
For these cases, SSE eliminates unnecessary complexity. WebSockets require both ends to implement bidirectional message handling, maintain frame encoding, and deal with connection lifecycle events. SSE clients just listen for events. The server writes plain text to a stream, using tools and patterns familiar from any HTTP response.
The unidirectional design also clarifies architecture. Request-response commands use POST/PUT/DELETE with standard REST or RPC semantics. Real-time updates flow over SSE. This separation makes systems easier to reason about, test, and debug. WebSocket connections that carry both commands and notifications blur these boundaries.
Connection Reliability
SSE’s automatic reconnection behavior handles many failure modes transparently. When a connection drops, EventSource waits a few seconds and reconnects, picking up where it left off if the server supports the Last-Event-ID header. The browser manages this without application code.
Compare this to WebSocket reconnection, which applications must implement themselves. Every WebSocket client needs exponential backoff logic, state synchronization on reconnect, and handling for the gap between disconnect and reconnect. These aren’t difficult problems, but they’re boilerplate that SSE solves by default.
The text-based protocol also makes SSE more debugger-friendly. Developers can watch events in browser network tools, curl an SSE endpoint to see the raw stream, or grep server logs for the exact bytes sent. WebSocket’s binary framing requires specialized tools to inspect traffic.
Scaling Considerations
SSE’s stateful connection model creates the same scaling challenges as WebSockets. Each connected client holds an open socket and some amount of server memory. Fan-out becomes the primary concern: when an event needs to reach thousands or millions of clients, the server must write to each connection.
This is where message brokers and pub-sub systems enter. Application servers subscribe to topics and forward events to their connected clients. Redis Streams, NATS, Kafka, and similar systems handle the fan-out from publishers to subscriber pools. The pattern works identically for both SSE and WebSockets.
HTTP/2 multiplexing helps SSE scale more efficiently than its reputation suggests. A single TCP connection carries multiple event streams, reducing per-connection kernel overhead. A client subscribed to five different event streams opens one connection, not five.
Operational Friction Points
SSE has practical limitations. Some corporate proxies still don’t handle long-lived HTTP connections well, closing them after arbitrary timeouts. This matters less than it once did, but edge cases remain. WebSockets can face similar issues, but its explicit upgrade handshake sometimes receives special handling.
Cross-origin requests require proper CORS headers, standard for any HTTP API but worth noting for real-time protocols. The server must handle preflight requests and set Access-Control headers appropriately.
Browser connection limits per domain affect SSE more than WebSockets because SSE uses the same counter as normal HTTP requests. Browsers typically allow six connections per domain, and each EventSource stream counts against this limit. In practice, applications rarely hit this ceiling, but it’s a factor for clients opening many streams.
The WebSocket Comparison
WebSockets excel when bidirectional communication happens frequently. Chat applications, collaborative editing, and multiplayer games all need low-latency messages flowing both directions. The full-duplex nature reduces latency compared to sending client commands over separate HTTP requests.
But many systems marketed as requiring WebSockets actually work fine with SSE. If client messages are infrequent, the overhead of separate HTTP requests is negligible. The architectural simplicity and operational familiarity of HTTP often outweigh theoretical latency concerns that don’t materialize in real usage.
The choice depends on traffic patterns, not dogma. Analyze whether your clients send messages constantly or occasionally. Measure whether request latency actually affects user experience. Choose the simpler protocol unless complexity buys something measurable.
Where SSE Fits Today
Server-Sent Events occupies a sweet spot for server-to-client notifications in systems that don’t need bidirectional real-time communication. It leverages existing HTTP infrastructure, simplifies client and server implementation, and provides built-in reconnection handling.
The protocol isn’t fashionable, but fashion isn’t architecture. For progress indicators, live feeds, monitoring dashboards, and notification streams, SSE delivers real-time updates without the ceremony of more complex alternatives. Sometimes the overlooked solution is overlooked precisely because it just works.