2dbi

Design WhatsApp

viaLeetCode

Problem Design a WhatsApp-style messaging system supporting 1:1 and group chats — covering both HLD and selected LLD details.

Functional requirements

  • Send/receive messages 1:1 and in groups; delivery states (sent/delivered/read); message history/sync across a user's devices; offline delivery on reconnect.

Non-functional requirements

  • Scale to discuss: 1B+ users, tens of billions of messages/day; delivery latency < ~200 ms online; no message loss (at-least-once + dedupe); end-to-end encryption.

Key components

  • Connection layer: persistent WebSocket gateways, user → gateway routing via a session registry.
  • Messaging service: per-conversation sequencing, message store (write-optimized wide-column DB e.g. Cassandra, partitioned by conversation, clustered by message id/time), delivery-receipt pipeline.
  • Group fan-out: sender uploads once → server fans out to member sessions; contrast with client-side fan-out for small E2EE groups (sender keys make server fan-out of one ciphertext possible).
  • Offline path: per-device queues; push notification to wake the app; sync on reconnect from last-acked id.

Deep dives / trade-offs

  • Retry for one failed group member: per-recipient delivery state, exponential backoff to that device's queue only — never re-fan-out.
  • Schema for history: (conversation_id, message_id) clustering; per-device read cursors; retention/TTL.
  • E2EE: Signal protocol at a high level (identity/prekeys, ratcheting), sender keys for groups, and what the server consequently cannot do (no server-side search/content filtering).
Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account