Discord uses WebSockets to instantly broadcast chat messages and voice room presence states to millions of connected desktop clients with zero HTTP polling latency.
Visual representation of control loops, memory layout, and execution flow for WebSockets & Real-time Protocols.
Client sends HTTP request with header `Upgrade: websocket` and `Connection: Upgrade`.
Server responds with `101 Switching Protocols` status code.
HTTP connection upgrades to persistent binary/text frame bidirectional WebSocket protocol.
| Feature / Dimension | WebSockets | Server-Sent Events (SSE) |
|---|---|---|
| Direction | Full-Duplex (Bidirectional client <-> server) | Unidirectional (Server -> Client push only) |
| Protocol | Custom WS frame protocol over TCP | Standard HTTP text/event-stream |
Detailed answers, interviewer pro tips, key takeaway summaries, and code examples formulated for technical rounds.
✅ Correction: Polling wastes server bandwidth and CPU creating new HTTP connections; WebSockets maintain 1 persistent socket connection.
Persistent bidirectional full-duplex TCP application protocol.