- When should I use WebSockets?
- Real-time bidirectional communication — chat, multiplayer games, live dashboards, collaborative editing. Not for request-response (use HTTP/2 with keep-alive).
- How does the lifecycle work?
- HTTP request with Upgrade header. Server accepts with 101 Switching Protocols. Now it's a raw TCP-like duplex channel. Messages can flow either direction anytime.
- What breaks in production?
- Load balancer misconfigured for long-lived connections, firewalls idling out connections, and scale: each WS connection holds a process/thread/memory. Plan capacity per connection.
- Alternatives?
- Server-Sent Events for server→client only (simpler). WebTransport (HTTP/3 based) for modern use. MQTT for IoT. Pick the simplest that fits the use case.