Real-time System Design
Real-time communication protocols, architectural patterns, and scaling for live data delivery
Long polling: client repeatedly requests server; wasteful but works everywhere. Server-Sent Events (SSE): server pushes updates over HTTP; unidirectional (client cannot send).
Works with proxies. WebSocket: upgrades HTTP to persistent bidirectional connection; lower overhead.
Binary or text frames. Supports custom heartbeats.
Choice: polling for simple apps, SSE for server->client updates, WebSocket for interactive apps. Latency: polling (seconds), SSE (milliseconds), WebSocket (milliseconds).
Scalability: WebSocket requires persistent connections (more memory). Real-world: Slack uses WebSocket; Twitter uses both; financial apps use WebSocket for low-latency updates.
Key Takeaways
Visual Diagram
Polling: Client asks repeatedly SSE: Server pushes to client WebSocket: Client <-> Server bidirectional