404human Projects Writing Build logs Learning Books Progress
Rust · Zola
zsh · 404human@dev:~ Tab complete · ↑↓ history · type help

SSE vs WebSockets vs Polling for live dashboards

SSE vs WebSockets vs HTTP polling for live dashboards: reconnect gaps, proxy timeouts, same-origin auth cookies, and operational simplicity.

Published
Read time
2 min read
Kind
guide
Topics

Use Server-Sent Events (SSE) for live dashboards, status feeds, and change notifications where updates flow server → browser. SSE runs over plain HTTP, works cleanly with standard session cookies and reverse proxies, and automatically reconnects in the browser. Use WebSockets only when you genuinely need low-latency bidirectional messaging (chat, collaborative editing, multiplayer state). Use plain polling when updates happen every 15–60 seconds and you want zero long-lived connections.

In Colophon CMS, live Studio updates use SSE backed by Postgres LISTEN/NOTIFY change hints (events.rs)—never WebSockets. Here is why.

SSE vs WebSockets vs Polling at a glance

DimensionPollingServer-Sent Events (SSE)WebSockets
DirectionRequest / responseServer → Client (one-way)Full-duplex (bidirectional)
ProtocolPlain HTTPPlain HTTP (text/event-stream)Upgrade: websocket (separate framing)
Browser auto-reconnectN/ABuilt into EventSource (+ Last-Event-ID)Manual (must build backoff + heartbeat)
Auth & cookiesStandard cookies / headersStandard same-origin cookiesNo custom headers in browser API; careful with CSWSH
Reverse proxy & HTTP/2Zero frictionWorks over HTTP/2 multiplexing (no 6-conn limit!)Separate TCP upgrade; extra proxy & idle timeout config
Best fitSlow-changing metrics, simple appsLive dashboards, deploy logs, AI token streaming, CMS updatesChat, collaborative whiteboards, games, live cursors

The hidden failure mode in every live stream: the reconnect gap

Whether you choose SSE or WebSockets, connections will drop—when a laptop sleeps, a proxy restarts, or a mobile user walks into an elevator.

The biggest mistake teams make is treating a live stream as the source of truth instead of a change hint:

  1. Stream hints, not full state. Send a tiny event ({ "kind": "resync" } or { "collection": "posts" }) and let the dashboard re-fetch the authoritative HTTP endpoint.
  2. Handle backend gaps explicitly. If your SSE server is fed by Postgres LISTEN/NOTIFY, remember that sqlx::PgListener::recv() silently drops notifications on reconnect. Loop on try_recv(), and when Ok(None) fires, push an explicit resync event to every connected browser tab so no UI silently goes stale.
  3. Send periodic keep-alive comments (: keepalive\n\n). Cloudflare, Caddy, and corporate proxies close idle HTTP streams after 60–100 seconds of silence. A 15-second SSE comment keeps the pipe open cleanly.

When to choose which

Choose Polling if:

  • A 10–30 second refresh interval is completely fine and you want stateless, CDN-cacheable HTTP endpoints.

Choose SSE if:

  • You need instant server-to-browser updates (dashboards, build logs, job progress, AI streaming) without maintaining a separate WebSocket protocol.
  • You serve your dashboard and API on the same origin with HttpOnly session cookies.

Choose WebSockets if:

  • The browser sends high-frequency messages back to the server (keystrokes, cursor coordinates, chat frames, binary telemetry) where per-message HTTP POST overhead would hurt.

Related reading