Home/Labs/Real-Time Protocol Race
All 280 Labs
INTERACTIVE LAB🔔

Real-Time Protocol Comparison Lab (Interactive)

One hour of events across four protocols: compare header waste, delivery latency, and fleet bandwidth. Dial event rate, poll interval, and client count to compute per-protocol hourly bandwidth, empty-poll waste, and useful-payload share across polling, SSE, and WebSockets.

Short Poll vs Long Poll vs SSE vs WebSocket

One hour of real-time traffic: measure header waste, delivery latency, and fleet bandwidth per protocol.

One text/event-stream HTTP response; server pushes UTF-8 chunks unprompted.

Workload

Unidirectional feed (ticker/AI tokens): SSE stays simplest — standard HTTP/2, native EventSource reconnect with Last-Event-ID.

Avg delivery latency25ms
Fleet bandwidth / hour51.4 MB
Bytes per client / hour51,400 B
Useful-payload share84%

Overhead accounting (per client-hour)

HTTP header bytes (~1KB/request)2,000

Event payloads43,200 B

Stream/frame framing7200 B

Decision rule: both ways, high frequency → WebSockets · server→client only → SSE · legacy firewall fallback → long polling · never short-poll hot feeds.

How It Works Under the Hood

Real-time delivery has four escalating designs. Short polling re-sends ~1KB of HTTP headers on a timer and mostly returns empty — 98% waste. Long polling hangs each request until an event fires, but still re-pays headers and TCP/TLS setup per message. SSE opens one text/event-stream over standard HTTP/2, sends headers once, and gets native EventSource reconnection with Last-Event-ID — which is exactly why ChatGPT streams tokens with it. WebSockets finish the ladder: a 101 upgrade to full-duplex 2-6 byte frames for chat and games, at the cost of custom reconnect logic and firewall risk.

Core Architectural Principles

  • Short polling wastes a full ~1KB header pair per poll; empty-response share grows with events-per-interval.
  • SSE: headers paid once, tiny per-event framing, built-in reconnect — unidirectional server→client only.
  • WebSockets: 2-6 byte frames, bidirectional, ~8ms latency, but manual reconnection and raw-TCP firewall exposure.
Interview Round Script

Use the decision rule out loud: high-frequency both ways means WebSockets; server-to-client only means SSE; long polling is a legacy firewall fallback; short polling never for hot feeds. Justify ChatGPT-style token streaming with SSE: HTTP/2 multiplexing, gateway auth headers, and EventSource auto-reconnect with Last-Event-ID.

Key Trade-Offs

Polling is simplest and most compatible; streams cut bandwidth and latency by orders of magnitude but add connection-state and reconnect complexity.

Related Curriculum Chapter

Long Polling vs Short Polling vs WebSockets vs SSE

Read Full Chapter Blueprint

Explore More Interactive Labs

View All 280 Labs