Purpose
Architect reliable, low-overhead real-time messaging protocols over WebSockets or Server-Sent Events (SSE), incorporating connection lifecycle handshakes, heartbeat ping/pong keep-alives, exponential reconnect backoff, channel multiplexing, and reconnection state recovery.
When to Use
- Building real-time collaborative editors, live chat, trading dashboards, or notification feeds.
- Fixing zombie WebSocket connections that silently drop behind NAT firewalls.
- Implementing message ordering and missed message replay after temporary disconnection.
What to Analyze
- Protocol Selection: WebSocket (bidirectional) vs SSE (unidirectional server-to-client with native HTTP/2 multiplexing).
- Frame Format: Lightweight JSON envelopes vs Binary MessagePack/Protobuf for high-frequency data.
- Heartbeat & Liveness: 30-second ping/pong frames to detect dead sockets through intermediate proxies.
- Reconnection & Catch-Up: Client reconnects with
last_event_id; server streams missed events from Redis buffer. - Authentication & Authorization: Ticket-based token exchange during connection handshake vs query param auth.
Output Format
- Message Envelope JSON Schema: Standard frame format (
type,channel,id,payload,ack). - Connection State Machine: Client connection lifecycles (
CONNECTING,CONNECTED,RECONNECTING,CLOSED). - Server/Client Implementation Snippets: TypeScript / Node / Go socket handler with ping/pong management.
Avoid
- Authenticating sockets by passing static JWT tokens in URL query strings (leaks into proxy access logs).
- Missing backpressure controls when broadcasting to slow mobile clients.


