You are tasked with designing a mobile and web messaging platform similar to WhatsApp, Telegram, or Meta Messenger. The system must support real-time one-on-one text conversations between users, allowing them to send and receive messages instantly, track delivery and read status, and see when contacts are online. Users expect their conversation history to sync seamlessly across multiple devices (phone, tablet, desktop) and to be able to send messages even when temporarily offline.
Your design must handle billions of users exchanging tens of billions of messages daily, with strict latency requirements (messages delivered in under 200ms when both parties are online) and high availability expectations (99.95% uptime). The system should gracefully handle network partitions, device failures, and bursty traffic patterns while maintaining message ordering and preventing duplicates.
Based on real interview experiences, these are the areas interviewers probe most deeply:
Interviewers want to see how you ensure messages arrive exactly once (from the user's perspective) in the correct order, even with network retries, multiple devices, and distributed infrastructure. This tests your understanding of distributed systems fundamentals and idempotency.
Hints to consider:
A core challenge is maintaining persistent bidirectional connections for billions of concurrent users while routing messages efficiently. Interviewers probe how you distribute connection state, handle reconnections, and avoid single points of failure.
Hints to consider:
When a user has multiple active devices, all must show the same conversation state. Interviewers look for explicit strategies to sync message history, read receipts, and typing indicators without creating race conditions or inconsistencies.
Hints to consider:
Storing and retrieving message history efficiently at scale requires careful data modeling. Interviewers evaluate your ability to choose appropriate storage systems, partition data, and handle hot conversations without performance degradation.
Hints to consider:
Presence (online/offline status) generates enormous write volume but has relaxed consistency requirements. Interviewers want to see how you optimize this high-frequency, low-value signal without overloading your system.
Hints to consider:
Begin by confirming the scope and constraints. Ask whether the system needs to support group chats or only one-to-one conversations. Verify the scale expectations: how many daily active users, what message volume, and what read-to-write ratio. Clarify expectations around multimedia (images, videos) versus text-only. Confirm whether end-to-end encryption is required, as this impacts delivery tracking. Establish latency targets for different operations (send, receive, sync). Determine if search functionality for message history is in scope.
Sketch the core components: client applications (mobile, web), API gateway layer, WebSocket gateway servers for persistent connections, message ingestion service, message queue/log (Kafka), message delivery workers, conversation storage (Cassandra or similar), cache layer (Redis), and presence service. Draw the message flow: sender device posts message to API, message ingested into Kafka partitioned by conversation ID, delivery worker reads from Kafka and pushes to recipient's WebSocket connection(s), acknowledgments flow back through the system. Show how presence updates flow through a separate lightweight path.
Focus on the message delivery pipeline and ordering guarantees. Walk through how a message flows from sender to recipient: sender generates UUID idempotency key and local sequence number, posts to ingestion API which validates and writes to Kafka partition based on conversation hash, delivery worker consumes from partition (maintaining order), looks up recipient device connections in Redis routing table, pushes to each connected device via WebSocket, stores message in Cassandra with (conversation_id, timestamp) as composite key. Explain how retries use the idempotency key to prevent duplicates, and how sequence numbers let devices detect and request missing messages during reconnection.
Discuss multi-device sync: each device maintains a watermark of the last message it received; on reconnection, devices request all messages after their watermark. Explain read receipt handling: track read status per device, use maximum across devices as user-level read state. Cover presence: maintain in-memory map of user-to-status in presence service, batch updates every 5 seconds, fan-out only to subscribed contacts. Address offline handling: client queues messages locally, retries with exponential backoff when connection restored. Mention monitoring: track message delivery latency percentiles, connection churn rate, queue lag, and storage hot partitions. Discuss horizontal scaling: shard WebSocket gateways by user hash, partition Kafka by conversation ID, use Cassandra's native sharding.