← Back to All Questions
Medium~60 minMessaging Systems

Design WhatsApp/Messenger - Real-Time Chat System

MetaWhatsAppSlackDiscordMicrosoftUberAmazon

📝 Problem Description

Design a real-time messaging application like WhatsApp or Facebook Messenger that supports 1:1 conversations, group chats, media sharing, read receipts, and online presence indicators. The system should handle billions of messages per day with sub-second delivery latency.

👤 Use Cases

1.
User wants to send a text message to a friend so that the message is delivered in real-time
2.
User wants to create a group chat with friends so that all members can send and receive messages
3.
User wants to send an image or video so that the media is uploaded and shared with recipients
4.
User wants to check if a message was delivered/read so that they see delivery and read receipts
5.
User wants to see if a friend is online so that they see real-time presence status
6.
User wants to search message history so that they find old conversations

✅ Functional Requirements

  • Send and receive text messages in real-time
  • Support group chats (up to 256 members)
  • Send images, videos, and files (up to 100MB)
  • Show online/offline/last seen status
  • Message delivery and read receipts (✓ ✓✓)
  • Message history and search
  • Typing indicators
  • End-to-end encryption for privacy

⚡ Non-Functional Requirements

  • Message delivery latency < 100ms within region
  • Support 2 billion users, 100M DAU
  • Handle 100 billion messages per day
  • Message ordering guarantee within conversation
  • High availability (99.99%)
  • At-least-once delivery (no lost messages)

⚠️ Constraints & Assumptions

  • Messages must be delivered even if recipient is offline (store and forward)
  • Message order must be preserved within a conversation
  • Group size limited to 256 members (to avoid fanout issues)
  • Media files up to 100MB per file
  • End-to-end encryption required (server cannot read messages)

📊 Capacity Estimation

👥 Users
2B registered users, 100M DAU
💾 Storage
100PB for messages and media
⚡ QPS
Messages: 1.2M/sec, Presence updates: 500K/sec
🌐 Bandwidth
50PB/month for media transfer
📐 Assumptions
  • 100M daily active users
  • 100 billion messages per day = 1.2M/sec
  • Average message size: 100 bytes
  • 10% of messages contain media
  • Average media size: 500KB
  • 500M group chats, average 10 members

💡 Key Concepts

CRITICAL
WebSocket for Real-Time
Persistent bidirectional connections enable instant message push without polling. Each gateway handles millions of connections.
CRITICAL
Message Ordering
Use sequence numbers or TimeUUIDs to guarantee message order within a conversation. Clients buffer and reorder if needed.
CRITICAL
Store and Forward
Messages for offline users are stored and delivered when they reconnect. Queue in Redis, persist in Cassandra.
HIGH
Presence with Heartbeat
Clients send heartbeat every 30s. If missed, mark offline. Use Redis TTL keys for automatic expiry.
HIGH
End-to-End Encryption
Signal Protocol for E2E encryption. Server only stores encrypted blobs, cannot read content.
MEDIUM
Delivery Receipts
Three states: Sent (server received), Delivered (recipient received), Read (recipient opened). Track via ACKs.

💡 Interview Tips

  • 💡Start with the WebSocket architecture - it's fundamental to real-time
  • 💡Discuss message delivery guarantees early (at-least-once)
  • 💡Draw the message flow from sender to receiver
  • 💡Mention E2E encryption as a key feature
  • 💡Cover offline handling - store and forward pattern
  • 💡Discuss presence system with heartbeat mechanism