Back to Tutorials

Real-time System Design

Real-time communication protocols, architectural patterns, and scaling for live data delivery

85 minutes
12Detailed Sections
Senior Level

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

1
Long Polling: Client repeatedly asks server; simple, high overhead, high latency
2
Server-Sent Events (SSE): Server pushes unidirectional; works with proxies
3
WebSocket: Bidirectional persistent connection; lowest latency, persistent overhead
4
Latency: Polling (seconds), SSE/WebSocket (milliseconds)
5
Memory Cost: WebSocket requires open connection per user (~1-5KB)
6
Best Choice: Polling for simple, SSE for updates, WebSocket for interactive

Visual Diagram

Polling: Client asks repeatedly
SSE: Server pushes to client
WebSocket: Client <-> Server bidirectional

Sign in to unlock

Sign In Free