WebSockets enable full-duplex communication over a single TCP connection:
Handshake: Starts as HTTP, upgrades to WebSocket
GET /chat HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Use cases:
- Real-time chat
- Live notifications
- Collaborative editing
- Gaming
- Live dashboards
Trade-offs:
- Persistent connections (more server resources)
- Harder to scale (sticky sessions or pub/sub)
- Not cacheable
Use WebSockets when you need real-time, bidirectional communication.