Choose between polling, SSE, and WebSockets, then make real-time updates reliable: reconnect with backoff, resume from the last sequence number, drop duplicates, detect gaps, and batch high-frequency updates so the UI stays smooth.
"Real-time" covers very different needs: a chat, a stock ticker, a collaborative cursor, a "your order shipped" toast. Pick the simplest transport that meets the latency and direction you need:
| Transport | Direction | Latency | Good for | Costs |
|---|---|---|---|---|
Polling (GET every N seconds) | Client pulls | Up to N seconds | Dashboards that tolerate delay, simple status checks | Many empty responses; latency vs. load trade-off |
| Long polling | Client pulls, server holds the request | Low | Fallback when nothing else works | A request per message; awkward to scale |
| Server-Sent Events (SSE) | Server → client | Low | Notifications, feeds, progress, live scores, AI token streaming | One direction only; text only |
| WebSocket | Both ways | Lowest | Chat, multiplayer, collaborative editing, trading | Stateful connections to scale; you implement reconnects, heartbeats, and resume |
| WebTransport | Both ways, multiple streams | Lowest | Games, media, unreliable/unordered delivery | Newer; browser and server support still varies |
Two points architects often miss:
EventSource reconnects automatically and sends Last-Event-ID so the server can resume. If the client only needs to receive, SSE plus normal POST requests for sending is often simpler than WebSockets.The rest of this tutorial focuses on WebSockets, because they leave the most reliability work to you.