Back to roadmap
Module 9 · Protocols, Security, ObservabilityDay 08225 min

WebSockets and Server-Sent Events

Push, not poll.

Day 082

WebSockets and Server-Sent Events

Client
client
WS server
service
SSE server
service
Signal path
Push vs poll
Client
client
duplex
WS server
service
SSE server
service
push
Client
client
Memory hook

WebSockets and Server-Sent Events: push, not poll

Mental model

design for the day something breaks

Design lens

WebSocket needs CORS-equivalent and load balancer support.

Recall anchors
WebSocketsSSE

Why it matters

WebSockets give bidirectional, frame-based messaging on a long-lived connection. Server-Sent Events (SSE) give simple server-to-client push over HTTP. Both reduce polling and enable realtime UX.

Deep dive

WebSockets: full duplex, binary frames, custom subprotocols. Broad use: chat, games, live data.

SSE: text/event-stream over HTTP — simpler, restarts/reconnects baked in.

Plan reconnection (backoff + last-event-id), heartbeats, and per-connection state.

Demo / scenario

Live order updates dashboard.

  1. Use SSE — server pushes 'order.updated' events.
  2. Client reconnects on disconnect with Last-Event-ID.
  3. Server resumes from that id.
  4. Idempotent UI updates handle duplicates.

Tradeoffs

  • WebSocket needs CORS-equivalent and load balancer support.
  • SSE is simpler but unidirectional.
  • Long-lived connections complicate scaling — pin sessions or use sticky shards.

Diagram

duplexpush
Client
WS server
SSE server
Push vs poll.

Mind map

Check yourself

Loading quiz…

Sources & further reading