Real-Time Apps Overview
A real-time application pushes data to clients the instant it changes, rather than making them ask repeatedly. Chat, live dashboards, collaborative editors, multiplayer games, notifications, live sports scores — all need the server to initiate communication, which ordinary request/response HTTP can't do. Node is exceptionally well-suited to this: its event-driven, non-blocking model lets a single process hold tens of thousands of open connections cheaply. This page frames the problem, compares the techniques (polling, long polling, SSE, WebSockets), and helps you pick the right one — before later pages dive into WebSockets, Socket.IO, and SSE.
Why plain HTTP isn't enough
The techniques compared
Technique | Direction | How it works | Best for |
|---|---|---|---|
Short polling | Client pulls | Client requests on a timer (every N sec) | Simple, infrequent updates; legacy support |
Long polling | Client pulls (held) | Server holds the request open until data, then client re-asks | Fallback when WS/SSE unavailable |
SSE | Server → client (one-way) | One long-lived HTTP stream, server pushes events | Server-to-client feeds: notifications, dashboards |
WebSockets | Bidirectional | Full-duplex persistent TCP connection | Two-way, low-latency: chat, games, collaboration |
Polling — simple but costly
// Short polling — the client asks on a fixed timer regardless of whether anything changed:
setInterval(async () => {
const res = await fetch('/api/messages?since=' + lastId)
const messages = await res.json()
if (messages.length) render(messages) // usually [] — a wasted round-trip
}, 3000) // 3s latency on updates, constant traffic even when idleChoosing the right technique
Server → client only? (notifications, live feeds, dashboards, progress) → SSE — simpler than WebSockets, runs over plain HTTP, auto-reconnects.
Bidirectional & low-latency? (chat, multiplayer, collaborative editing) → WebSockets.
Want fallbacks, rooms, and reconnection handled for you? → Socket.IO (a library on top of WebSockets).
Infrequent updates, maximum simplicity, no infra changes? → polling may be fine.
Behind restrictive proxies/firewalls? → SSE/long-polling often pass more reliably than raw WebSockets.