Skip to content

Real-time Protocols — Notes#

Heartbeat / keep-alive#

  • WS: send ping frame every 20-30 s; close conn if no pong in 2× interval.
  • SSE: send : comment\n\n every 15 s.
  • Long-poll: set server response timeout < intermediary idle timeout.

Backpressure#

  • WS / SSE have no built-in flow control — application must drop or coalesce on slow clients.
  • gRPC streaming uses HTTP/2 flow control (per-stream + connection windows).

Auth at the edge#

  • Use cookies or Authorization header for HTTP-based (SSE).
  • For WS, browsers can't set custom headers on the upgrade — pass auth as query param or sub-protocol, or do an HTTP login first that sets a cookie.

Capacity#

  • Plan ~10 KB RSS per idle WS connection.
  • 200k conns × 10 KB = 2 GB per gateway box; tune fs.file-max, net.ipv4.tcp_*.

Refs#

  • RFC 6455 (WebSocket), WHATWG SSE spec.
  • "Designing for Throughput" — Cloudflare Workers WS blog.
  • Slack / Discord / Phoenix Channels architecture posts.