WebSocket Design
Realtime needs auth on connect, heartbeats, reconnect/resume, and backpressure. Do not treat sockets as free unlimited fan-out.
Workflow
- Use cases: notifications, collab, trading, presence.
- Auth: ticket/token on connect; revalidate on resume.
- Protocol: message types, versioning, compression.
- Scaling: sticky sessions, pub/sub fan-out, room design.
- Reliability: heartbeats, backoff reconnect, offline buffer.
- Backpressure and max message size.
- Observability: connects, drops, lag.
Output format
## Realtime design
**Channels:** …
**Auth:** …
**Message schema:** …
**Reconnect/resume:** …
**Scale plan:** …
**Limits:** …
Rules
- Authenticate before subscribing to private rooms.
- Validate every client message; never trust client as authority for money.
- Document idle timeouts and ping/pong.
- Prefer idempotent event ids for delivery.
- Separate public broadcast from private streams.
Edge cases
- Mobile networks: aggressive reconnect.
- Horizontal scale: avoid single-node presence without store.
- Browser limits: connection count per origin.