Skip to content
← Notes

WebSockets

Real-time, pub/sub, presence, backpressure

  1. 00 WebSockets & realtime — Roadmap Ten chapters that go from 'what is the WebSocket handshake' to a self-hosted, horizontally scaled realtime server with Redis pub/sub, presence, auth, and nginx in front.
  2. 01 What WebSockets are and when to use them A WebSocket is a bidirectional, persistent TCP connection that starts life as an HTTP request. Useful when neither REST nor RPC fits. Misused often.
  3. 02 The handshake and frame protocol RFC 6455 in the parts that matter for shipping a server. Upgrade headers, frame layout, masking, opcodes, close codes, and the rules a library follows so you do not have to.
  4. 03 Your first server End-to-end Go WebSocket server in eighty lines, with a browser client. By the end you have an echo service plus a tiny chat room — both running on localhost, both real.
  5. 04 Message protocols on top Raw frames carry bytes. Real apps need types, versions, and request/response correlation. Designing the message envelope before you have ten clients in the wild saves you years of pain.
  6. 05 Server-Sent Events When the client only listens, SSE beats WebSockets in every dimension that matters — simpler protocol, free reconnect, plain HTTP. The default for one-way realtime.
  7. 06 Pub/sub at scale One process can hold thousands of connections; production needs many. The piece that makes that work is a pub/sub bus that fans events from any process to every connection on every other process.
  8. 07 Presence and rooms Knowing who is online and which channel they are watching looks easy in a one-process demo and is genuinely hard at scale. The data model is half the work; the eviction story is the other half.
  9. 08 Auth, origin, and rate limits WebSocket handshakes look like normal HTTP, which makes them subject to normal HTTP attacks plus a few WebSocket-specific ones. Verify origin, authenticate at the handshake, and rate-limit at every level you can.
  10. 09 Backpressure, reconnects, heartbeats Networks drop. Clients stall. Tabs sleep. The patterns in this chapter are the difference between a WebSocket service that runs for a week and one that limps for an hour.
  11. 10 Production self-host Behind nginx with TLS, systemd-managed, observable, scaled across processes via Redis. Same operational shape as the GraphQL and gRPC tracks — different protocol on the wire.