Real-time Updates
How a change on the server reaches every client that cares within a second or so: the connection to the client, the fan-out between servers, and the rules that keep updates from being lost or arriving out of order.
Overview
A real-time update is a change on the server that reaches the clients who care about it within about a second, without them asking. Chat messages, live scores, order tracking, stock prices, collaborative cursors and notification badges all work this way.
The web was built for pull: the client asks, the server answers. Real-time features need push, where the server sends data when it changes. That needs two things the plain request-response model does not give you: a connection the server can write to at any time, and a way for the server that learns about a change to find every server holding a connection that wants it.
That second part is where the design work is. Picking WebSocket or Server-Sent Events takes a minute in an interview. Explaining how a message written on one server reaches a million clients connected to a hundred others, in order, without losses when connections drop, is what interviewers are listening for.
What you will be able to do
- Split a real-time feature into its two hops and choose a mechanism for each.
- Route an update from the service that made it to every connected client, through a pub/sub layer.
- Keep clients correct across dropped connections with sequence numbers, resume and gap fill.
- Estimate fan-out cost, and protect the system from hot channels and slow clients.
- Deliver to users who are offline, and track who is online.
Key concepts
- Push and pull
- Persistent connections
- Connection registry
- Pub/sub fan-out
- Change data capture
- Sequence numbers and gap fill
- Backpressure
- Presence
- Offline delivery
Interview questions
- Design the real-time delivery for a chat app with millions of users.
- How do you scale WebSocket servers horizontally?
- How do you make sure clients do not miss or reorder messages?
- Redis Pub/Sub or Kafka for fan-out between servers?
- A live-stream chat has 100,000 viewers. What breaks, and how do you fix it?
- How would you add real-time order tracking to an existing e-commerce system?
- How do you handle a client that cannot keep up?
- How do you track which users are online?
Sign up free to read the full topic
More System Design topics
Start free on Cariara · Coding problems · System design studio