Real-time delivery
Pushing to a user the moment something happens, whether they are online or not.
When you finish, you should be able to say
Trace a message from sender to an offline recipient and back online, naming each hop.
The route
6 blocks (3 fundamental, 3 senior), then the practice problem.
- Push to the browser in real timeFundamental
- Find which server holds a userSenior
- Track online status cheaplySenior
- Deliver to users who are offlineSenior
- Reach devices through platform pushFundamental
- Simpler one-way pushFundamental
- Chat App (WhatsApp / Messenger)
Next, step 1 adds Connection server A, Connection server C (outlined). A box fills in when you tick “I can explain this” on the block that introduces it; plain boxes come from the problem itself.
The persistent connection that makes push possible, and the state it forces onto servers.
Chat, presence and live updates need server-to-client pushes, not polling.
Say it like this: Chat needs sub-second server push, so I hold one WebSocket per client on stateless connection servers and keep a registry of which server holds each user, so any service can route a message to the right socket.
Adds to the design: Connection server A, Connection server C
Check yourself: How does server A know that user B is connected to server C?
A shared registry, usually Redis, maps user id to connection server id with a TTL refreshed by heartbeats. A looks up B and either calls C directly or publishes to a channel C subscribes to. If the entry is missing, B is offline and the message takes the inbox-and-push path instead.
With thousands of connection servers, this is how you find the one holding a user.
Server A has a message for Bob, but Bob’s socket is on server C.
Say it like this: Sockets are stateful, so I keep a registry of user to connection server in Redis with a TTL refreshed by heartbeats, and any server can route a message by one lookup.
Adds to the design: Connection registry
Check yourself: How does server A actually get the bytes to server C?
Either a mesh of persistent internal connections between the chat service and every connection server, or a Pub/Sub channel per server that the chat service publishes to. Channels are simpler to operate because nobody maintains a connection to everyone; the mesh has slightly lower latency.
Online status without broadcasting to everyone, and why typing indicators are never stored.
Broadcasting every status change to every contact is N² traffic.
Say it like this: Presence is a last-seen timestamp with a TTL, refreshed by a batched heartbeat, and I publish changes only to the people who currently have that contact open, so it never becomes an all-to-all broadcast.
Adds to the design: Presence service
Check yourself: How do you detect that a user went offline without polling every key?
Let the TTL expire and do not publish anything; the next time a watcher opens the chat they read the current state. For watchers already subscribed, either Redis keyspace notifications on expiry or a short periodic scan of the watched users, which is a small set. Offline is allowed to be a minute late.
The recipient is not connected; the inbox-first design that guarantees delivery later.
The recipient has no connection; the message must arrive later and in order.
Say it like this: Delivery has to survive the recipient being offline, so every message is written to a durable per-user inbox before any push, and on reconnect the client sends its last cursor and drains the inbox in order.
Adds to the design: User inbox
Check yourself: What exactly is the cursor and who owns it?
The highest inbox_seq the client has stored and acked, kept by the client and sent on every reconnect. The server trusts it to resume from, and keeps rows above it until acked. Because inbox_seq is per user and monotonic, the cursor is a single integer regardless of how many conversations are involved.
Reaching a phone when the app is closed, through the platform’s own push service.
The app is closed; you cannot hold a socket.
Say it like this: When the app is closed I cannot hold a socket, so I send a small notification through APNs or FCM using the stored device token, and the app fetches the real content when it opens.
Adds to the design: APNs and FCM
Check yourself: Why is a push not a reliable delivery channel?
Providers deliver at most once and may drop, delay or collapse pushes, especially silent ones on low battery; a device that is off for a day receives only the last collapsed one. So the push is a hint to open the app, and the durable inbox or API is what guarantees the content arrives.
The simpler alternatives, so you can say when a WebSocket is overkill.
You need server pushes but WebSockets are blocked or overkill.
Say it like this: Updates only flow server to client here, so I use server-sent events over plain HTTP and keep long polling as the fallback for networks that cut idle connections.
Adds to the design: Long-poll endpoint
Check yourself: When would you pick SSE over WebSockets?
When data flows almost entirely from server to client and the client sends rarely: feeds, notifications, order status, dashboards. SSE needs no special protocol support, reconnects on its own, and runs through the same HTTP infrastructure as the rest of the API. WebSockets earn their complexity when the client sends many small messages.
Putting it together
How the blocks above combine into one design for Chat App. The numbers on the boxes are the steps that introduce each part.
The chat delivery path, assembled from the path Each number is a step of this path; a box with two numbers is shaped by both blocks. The ring colour is the block's category, as on the route map. Boxes without a number come from the problem itself. Point at a step below, or at a bubble, to see where it appears.
Clients hold WebSockets to interchangeable connection servers; the chat service finds the recipient through the registry and writes every message to the inbox before pushing it. Offline phones get a body-less platform push, and restricted networks fall back to long polling.
How each block shows up in the design
- 1. Push to the browser in real time: every client holds one WebSocket to a connection server behind a layer-4 load balancer, and each server holds about 250K sockets, so 250M concurrent users need roughly 1,000 cheap, interchangeable servers.
- 2. Find which server holds a user: on connect a server writes the user's server id into the Redis registry with a 60 s TTL refreshed on every heartbeat, so the chat service can route Bob's message to connection server C, and a crashed server's entries expire on their own.
- 3. Track online status cheaply: clients ping every 30 s and each connection server batches all of its users into one presence update, which turns 8M writes per second into about 33 (1,000 servers each writing once every 30 s, about 250K heartbeats per write); changes go only to users who have that contact or conversation open.
- 4. Deliver to users who are offline: the chat service writes every message to the recipient's inbox before pushing it and deletes the row only after the device acks, so a socket that drops mid-push loses nothing and a reconnecting client syncs from its last cursor.
- 5. Reach devices through platform push: when Bob has no live connection, the inbox write triggers an APNs or FCM notification with no message body, whose only job is to make him open the app so the socket reconnects and drains the inbox.
- 6. Simpler one-way push: clients on networks that block WebSockets fall back to long polling, where each request is held open until a message arrives; server-sent events suit notification-style feeds but not two-way chat, because sends would still need separate HTTP calls.
- ★
Chat App (WhatsApp / Messenger)
Now run the timed practice. The blocks above should appear in your answer without prompting; if one does not, that is the one to reread.
The same parts on other clouds
The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.
| AWS | Used here as | Google Cloud | Microsoft Azure | Open source and others |
|---|---|---|---|---|
| Amazon EC2 | Long-poll endpoint, Connection server A, Connection server C, Conn server A, Conn server C, Connection server, Stream server | Compute Engine | Azure Virtual Machines | DigitalOcean Droplets, any VM or bare metal |
| Amazon ElastiCache | Connection registry, Registry (Redis), Presence keys, Watchers set, Registry lookup, Replay buffer | Memorystore | Azure Managed Redis | Redis, Valkey, Memcached |
| Amazon EC2 Auto Scaling | Chat service, Presence service, Sync service, Push sender, Content API | Compute Engine managed instance groups | Virtual Machine Scale Sets | Kubernetes Deployment with a HorizontalPodAutoscaler, Nomad |
| Amazon Keyspaces | User inbox, Message store, Inbox (per device) | Bigtable | Managed Instance for Apache Cassandra | Apache Cassandra, ScyllaDB |
| Amazon DynamoDB | Device tokens | Firestore, Bigtable | Cosmos DB | ScyllaDB, Apache Cassandra |
| Amazon SQS | push queue | Pub/Sub, Cloud Tasks | Service Bus queues, Queue Storage | RabbitMQ, ActiveMQ |
| Application Load Balancer | Load balancer | Cloud Load Balancing | Application Gateway, Azure Load Balancer | NGINX, HAProxy, Envoy |
| Amazon EventBridge | Event bus | Eventarc | Event Grid | Knative Eventing |