Real-Time Updates
Chat messages, live scores, ride tracking, collaborative editing and notifications all ask the same question: when something changes on the server, how does the right user's screen find out within a second or two? This lesson is for software engineers preparing for system design interviews. It splits the problem into two halves that candidates often blur together, then covers ordering, reconnection and presence, which is where the follow-up questions land.
Two problems, not one
Server to client. Once a server knows about an update, how does it reach a browser or phone? Polling, long polling, server-sent events or WebSockets.
Producer to the right server. The update is created on one machine (the scoring service, the sender's chat server), but the recipient is connected to another of perhaps hundreds of connection servers. How does the update find that server?
Interviewers listen for whether you see both. Saying "we use WebSockets" answers the first half and leaves the second untouched.
Server to client: four options, simplest first
Short polling
The client asks "anything new?" every few seconds. It is plain HTTP, works everywhere, and every request can be served by ordinary stateless servers or even a CDN. The costs are latency (up to one polling interval) and wasted requests: 1 million clients polling every 5 seconds is 200,000 requests per second, most of which return nothing new. It fits when updates are infrequent, a few seconds of delay is fine, and the same data goes to everyone, so responses can be cached.
Long polling
The client sends a request and the server holds it open until there is news or a timeout (often 20 to 30 seconds), then the client immediately asks again. Latency drops to near zero and empty responses mostly disappear, but each waiting client holds an open request on a server, and a burst of updates causes a burst of reconnecting requests. It is a reasonable fallback where long-lived connections are blocked.
Server-sent events (SSE)
One long-lived HTTP response that the server keeps writing events into. It is one-way, server to client, which is all a scoreboard, feed or notification stream needs. Two features matter in an interview: the browser's EventSource reconnects automatically, and each event can carry an id, which the browser sends back as the Last-Event-ID header on reconnect so the server can resume where it left off.
WebSockets
A full-duplex connection upgraded from HTTP. Choose it when the client also sends frequent messages over the same channel: chat, multiplayer games, collaborative editing. It is the most capable and the most operationally demanding option: connections are stateful, load balancers must support them, and deploys have to drain them. Load Balancing in Depth covers draining and reconnect storms.
Tip
Pick the simplest option that meets the latency and direction requirements, and say why. "Updates flow one way and every viewer sees the same data, so SSE, not WebSockets" is a stronger sentence than naming the most powerful tool.
For mobile apps in the background, none of these run; the update goes through the platform push services (APNs on iOS, FCM on Android) instead, with the real-time channel resuming when the app is opened.
Producer to the right server
Suppose 2 million clients are spread across 40 connection servers. An update is produced somewhere else. Three ways to route it:
Pub/sub by topic. Each connection server subscribes to the topics its clients care about (
match:123,conversation:9). The producer publishes once; only subscribed servers receive it. This suits broadcast data where many users watch the same thing. The fan-out to servers is cheap: one message per subscribed server, not per user. Know the delivery guarantee of the layer you name. Redis pub/sub is fire-and-forget: a server that is disconnected or too slow at that moment misses the message, and nothing replays it. That is acceptable only because the sequence numbers and replay buffer below detect and fill the gap. A log (Kafka, Redis Streams) retains messages so a server can resume from an offset, at the cost of more to operate.Connection registry. Each server records "user U is connected to server S" in a shared store with a short TTL refreshed by heartbeat. To reach one user, look up their server and send the message there directly. This suits per-user messages such as direct chats and notifications.
Consistent hashing of users to servers. Route each user's connection to
hash(userId)on a ring of connection servers, so any service can compute where a user is without a lookup. The catch: adding or removing a server moves some users, who must reconnect, so it needs care during scaling and deploys.
Real systems mix them: topics for shared streams, a registry for individual users.
Ordering, gaps and reconnection
Connections drop constantly: phones change networks, laptops sleep, servers deploy. A real-time design is judged on what happens next.
Sequence numbers per stream. The single producer of a stream (the scoring service for one match, the server that owns a conversation's partition for one chat) stamps each event with an increasing sequence number. Clients ignore duplicates and detect gaps.
Resume from the last seen event. On reconnect the client sends the last sequence number it applied (
Last-Event-IDin SSE). The server replays newer events from a short buffer, for example the last 10 minutes of events per stream held in memory or in a log.Snapshot plus deltas. If the client was away longer than the buffer covers, it fetches the current state over a normal HTTP request, then resumes the stream from that snapshot's sequence number. This one pattern answers most "what if they were offline?" questions.
Presence
"Who is online" sounds small and is expensive. The usual design: the client sends a heartbeat every 30 seconds, the server sets presence:userId with a 60-second TTL, and a missing key means offline. The cost is fan-out of changes. A user with 500 contacts going online would notify 500 people, and at scale those notifications can dwarf real messages. Common mitigations are to fetch presence lazily when a conversation is opened, batch presence updates every few seconds, and stop broadcasting presence for very large groups.
Worked example: live match scores
Prompt: "Show live scores and commentary for a major match to 2 million concurrent viewers on web and mobile. Updates should appear within 2 seconds."
Numbers. Score changes are rare, perhaps a few per match; commentary lines arrive every few seconds. Every viewer of a match sees the same data.
Option A, polling plus CDN. Clients poll every 5 seconds, which is 400,000 requests per second, but the response is identical for everyone, so a CDN caches it for 1 second and the origin sees roughly one request per second per edge location. This is cheap and robust, but delay can reach about 6 seconds (the polling interval plus the cache TTL), which misses the 2-second goal.
Option B, SSE plus pub/sub. Viewers hold an SSE connection to a fleet of connection servers. Assuming about 50,000 connections per server, a figure to confirm by load test:
2,000,000 viewers / 50,000 per server = 40 connection servers (before headroom)
one event -> 40 pub/sub deliveries -> 2,000,000 pushes in total
commentary every 3 s -> each server sends ~50,000 events every 3 s (~17,000/s)The scoring service publishes each event with a sequence number to match:123; every connection server with viewers of that match is subscribed and forwards it. Reconnecting viewers send Last-Event-ID and get the missed events from a 10-minute buffer, or a fresh snapshot if they were gone longer.
Recommendation. Option B meets the latency goal, which is the requirement this prompt is scored on; keep Option A's polled endpoint as the fallback for clients that cannot hold a connection, and as the snapshot source. WebSockets are unnecessary because viewers send nothing back on this channel. If the interviewer adds live reactions from viewers, revisit that choice and say what changes.
What scores here: comparing two workable options against the stated 2-second requirement rather than naming one tool (trade-offs), and the connection-server count, fan-out and replay buffer (deep dive and scalability). A candidate who answers "WebSockets and Redis" has picked a heavier transport and still not said how a viewer who dropped for 30 seconds catches up.
Follow-ups to expect
"A connection server dies. What do its viewers see?" A short gap, then automatic reconnect with jittered backoff to another server, resuming from their last sequence number.
"How do you guarantee order?" One producer per stream assigns sequence numbers; clients reorder or refetch on a gap.
"Ten thousand matches at once, most with few viewers?" Servers subscribe only to topics their clients watch, so quiet matches cost almost nothing.
"Why not WebSockets everywhere?" They cost more to operate and add nothing for one-way streams.
What changes with seniority
A mid-level candidate should choose a transport with a reason and mention reconnection. A senior candidate separates the two halves, routes updates with pub/sub or a registry, and covers ordering, gaps and the snapshot-plus-deltas pattern. A staff-level candidate adds capacity math, fallback paths, behavior during deploys, and the presence fan-out cost before being asked.
Mistakes that cost points
Answering only the transport. "WebSockets" without saying how the update reaches the right server is half a design.
WebSockets by default. Choose by direction and latency; a one-way stream rarely needs them.
No plan for missed messages. Every real client disconnects; resume and snapshot are expected.
Unbounded presence fan-out. Broadcasting every status change to every contact does not scale.
Practice it
Spend 15 minutes choosing a transport and a routing method for three features of an app you use (notifications, a live feed, a shared document) and write one sentence justifying each. Then try Design a Real-Time Chat System, where both halves, ordering and presence all come up.
Practise this in a mock interview
Try what this lesson covers out loud: the AI interviewer asks one of these questions, follows up, and scores your answer.
- Design a URL ShortenerSystem Design · Medium
- Design a Rate Limiter ServiceSystem Design · Medium
- Design Live Score Alert FanoutSystem Design · Medium
- Design a Video Upload and Transcoding PipelineSystem Design · Medium
Read next
- Dealing with Contention: When Everyone Wants the Last Seat
Work out how many updates per second a hot row can take, then pick and defend the right fix: pessimistic or optimistic locking, atomic conditional updates, expiring holds, fenced distributed locks, queues or split stock.
8 min read
- Multi-Step Processes and Long-Running Jobs
Design flows that span services so they finish or cleanly undo themselves, with sagas, compensations, idempotent retries, the outbox pattern and durable workflows, and run long jobs with status, heartbeats and dead-letter queues.
8 min read
- Handling Large Files: Uploads, Processing and Delivery
Keep large files off your API servers with presigned and resumable multipart uploads, keep metadata and stored bytes consistent, process files after upload, and deliver them through a CDN with range requests.
7 min read
- Scaling Reads
Apply the read-scaling moves in order (fix queries, denormalize, add replicas, cache, precompute), check each against a read-rate estimate, and handle replication lag and hot keys.
8 min read
