OOmnistu

Blog / Web Fundamentals

Web Fundamentals

WebSockets vs server-sent events: picking the right realtime channel

SSE pushes one way over plain HTTP with automatic reconnect; WebSockets are bidirectional and stateful. A decision rule for chat, feeds, dashboards and streams.

OOmnistu
Reviewed 2026-11-19 · 3 min read

When a page needs live updates - chat, dashboards, order tracking, collaborative editing - the choice usually lands on WebSockets or server-sent events (SSE). They are not interchangeable, and picking the simpler one that fits is a real engineering saving.

This guide compares the two using MDN's documentation, checked on 19 November 2026.

What server-sent events are

Traditionally a page must request data from the server; SSE flips that for one direction: the server can push new data to the page at any time. The browser's EventSource interface handles connecting to the server, receiving events and data, handling errors and closing the connection. SSE runs over plain HTTP as a long-lived text stream, which brings practical gifts: it works through proxies and HTTP infrastructure without special handling, the browser reconnects automatically when the connection drops, and the API is a few lines of client code. SSE is also available in Web Workers, so processing can stay off the main thread.

What WebSockets are

WebSockets upgrade an HTTP connection into a persistent, bidirectional channel: after the handshake, both client and server can send messages at any time, in either direction, with low framing overhead. That bidirectionality is the entire point - and the entire cost. WebSocket connections are stateful, sit outside normal HTTP request-response handling, and need explicit decisions about reconnection, heartbeats, backpressure and horizontal scaling (which server holds which connection).

The decision rule

Practical notes before shipping either

A note on scaling

Both options hold one open connection per online user, which changes your capacity math from "requests per second" to "concurrent connections". A single small server can hold thousands of mostly-idle SSE or WebSocket connections, but application servers with per-connection threads or workers will run out far sooner than the network does. If you expect real scale, check how your framework handles concurrent connections before choosing either - and remember that every reconnect storm (a deploy, a network blip) arrives as a burst of simultaneous connection attempts your stack must absorb.

Sources

Drafted with AI assistance from this source. Connection behavior varies across proxies, hosts and client networks; test long-lived connections through your real infrastructure before launch.