Design Facebook chat messenger
Filed under Walmart
Free read 2 of 3Functional: 1:1 and group chat, history, receipts, presence, media. Non-functional: low latency for online users, no lost messages, ordering within a conversation, high availability. Clarify scale and group size limits; calls and end-to-end encryption can be called out of scope.
The question
Design a Facebook Messenger-style chat service supporting 1:1 and group conversations, real-time delivery, message history, delivery and read receipts, and online presence.
Constraints
- Assume hundreds of millions of daily users and tens of billions of messages per day (illustrative)
- Delivery under roughly 200 ms for online recipients
- Messages must not be lost and are ordered within a conversation
- Offline users receive messages after reconnecting
Approach
Functional: 1:1 and group chat, history, receipts, presence, media. Non-functional: low latency for online users, no lost messages, ordering within a conversation, high availability. Clarify scale and group size limits; calls and end-to-end encryption can be called out of scope.
Clients hold a persistent WebSocket to a chat gateway. A session registry (for example Redis) maps user to gateway. A chat service handles send logic, a message store holds history, a push service covers offline users, object storage plus a CDN holds media, and a presence service uses heartbeats.
Client sends to the gateway; the chat service assigns a per-conversation sequence id, persists the message (write to a queue such as Kafka, then a wide-column store keyed by conversation id and message id), looks up recipient gateways, pushes, and records acks. Offline users get a push notification and sync on reconnect.
Shard messages by conversation id and gateways by user with consistent hashing. Fan out group messages through a queue, capping group size or using pull for large groups. Cache recent messages. Throttle presence updates to avoid fan-out storms.
If a gateway dies, clients reconnect and fetch everything after their last seen sequence id. Use at-least-once delivery with client-side dedupe by message id, retries with backoff, and multi-region replication for the store.
Tips
- What they are testing: System design rounds like this typically probe your choice of real-time transport, ordering and delivery guarantees, and how you handle fan-out at scale.
- Common mistake: Using HTTP polling or one relational database for everything, and ignoring offline delivery, ordering and group fan-out.
Related Walmart questions
Collected from public candidate posts and coding forums. Updated Nov 2026.