Real-time communication · mid
Polling, long polling, SSE, WebSockets and WebTransport
Short polling asks repeatedly, long polling holds each request open until there is news, Server-Sent Events stream server-to-client text over plain HTTP with automatic reconnect, WebSockets give a full two-way channel, and WebTransport (Baseline since March 2026) adds multiple streams and unreliable datagrams over HTTP/3.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Short polling: simple, works everywhere, wastes requests and adds delay up to the interval. Fine for 'refresh every 30 s'.
- Long polling: the server holds the request until there is data or a timeout, then the client immediately asks again. Near real-time over plain HTTP.
- SSE (EventSource): one-way server -> client, text/event-stream format (data:, event:, id:, retry:), automatic reconnect with Last-Event-ID, works through normal HTTP infra. Over HTTP/1.1 browsers allow only 6 connections per domain (shared across tabs); HTTP/2 removes that problem.
- WebSocket: full-duplex messages over one upgraded TCP connection. Good for chat, collaboration, multiplayer. Needs its own reconnect, heartbeat, auth and scaling (sticky sessions or pub/sub). The WebSocket API has no backpressure.
- Streaming fetch (ReadableStream) is how most AI chat UIs stream tokens: a POST whose response body arrives in chunks.
- WebTransport: HTTP/3 + QUIC, multiple reliable streams plus unreliable datagrams, backpressure. Baseline newly available since Safari 26.4 (Mar 2026); still needs server support.
- Choose by direction (one-way or two-way), frequency, latency needs, infra (proxies, load balancers) and battery on mobile.
The red pen
Common traps: mistake → fix
Mistake: "Use WebSockets for everything real-time"
Fix: for server -> client updates (order tracking, notifications, live scores), SSE or polling is simpler and works with HTTP infra.
Mistake: "SSE can't reconnect or resume"
Fix: EventSource reconnects automatically and sends Last-Event-ID.
Mistake: "WebSockets reconnect by themselves"
Fix: they don't; you write reconnect with backoff.
Easy to hard
Questions interviewers ask, easy to hard
- Polling vs long polling vs SSE vs WebSockets: explain each.
- Live order tracking, a chat app and a stock ticker: which transport for each and why?
- How does an AI chat UI stream its answer?
- What is WebTransport and when would you consider it over WebSockets?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.