Server-Sent Events (SSE)
Most commonly on the web, HTTP involves the client repeatedly sending requests, and for each, the server sends back responses. This works for most applications but is not performant enough for real-time applications. The most performance-sensitive applications (like multi-player real-time games) use WebSocket sessions instead of normal stateless HTTP connections. This boosts performance but at the cost of complexity — now the server needs to manage both HTTP and WebSocket sessions. Plus, the WebSocket sessions are stateful and inherently more complex than HTTP sessions.
There’s a third option — Server-Sent Events (SSE), which is a middle ground between these two. SSE still uses HTTP machinery (so there’s less complexity), but like WebSockets, they are stateful. They are less performant than WebSockets but still fast enough for real-time applications like chat notifications. Unlike WebSockets, SSE is one-way (server → client), but this is sufficient for many applications.
So there’s a complexity vs. performance tradeoff, from the simplest to the most complex and performant:
- Normal HTTP → HTTP Server-Sent Events → WebSockets.