Realtime Transport: SSE vs WebSocket vs Long Poll

Select the right transport based on interaction model, reliability needs, and infra constraints.

Pattern level: macro

TL;DR

Choose WebSocket for frequent bidirectional interaction, SSE for simpler server-to-client streams, and long poll as compatibility fallback.

Problem this solves

  • Defines latency, ordering, and reconnect behavior for live updates.
  • Shapes infra complexity and cost for persistent connections.

Decision criteria

  • WebSocket: best for high-frequency duplex traffic.
  • SSE: best for one-way updates with simpler infra.
  • Long poll: best for environments with strict proxy/network constraints.

Layered depth

Intro

Transport choice is a product decision: latency profile, scale model, and developer ergonomics change together.

Decision criteria

Start with required interaction directionality and update frequency, then evaluate reconnect/replay needs.

Implementation detail

  • Define heartbeat and timeout policy per transport.
  • Standardize event envelope with sequence IDs across all transports.
  • Implement replay from snapshot + cursor to recover after disconnect.

Failure modes

  • Silent disconnects create stale UI with no reconnect attempt.
  • Sequence gaps after reconnect cause duplicate or missing state.
  • Proxy buffering breaks SSE freshness assumptions.

Pitfalls

  • Coupling domain events directly to transport protocol frames.
  • Ignoring fallback behavior for captive portals and constrained networks.

Testing and accessibility

Testing + Accessibility Rubric

CategoryLevelRequirementDone When
functionalunitIncoming events respect sequence and dedupe semantics.Out-of-order, duplicate, and missing event tests are all covered.
functionalintegrationReconnect path correctly hydrates snapshot and applies deltas.Reconnect test proves no duplicate rows or missing updates.
a11yintegrationLive updates are announced without overwhelming screen readers.Announcement batching and wording pass manual SR checks.
a11ye2eFocus remains stable when real-time updates occur.Keyboard-only user can continue primary task uninterrupted.

Production trade-offs

  • WebSocket improves interaction quality but requires stronger connection lifecycle handling.
  • SSE simplifies operations but is limited for duplex workloads.

Used In Case Studies

Related Patterns