Designing a Real-Time Chat & Messaging Platform (WhatsApp / Discord)
Design a high-concurrency real-time messaging platform using persistent WebSocket connections, ephemeral session routing, distributed message queues, and end-to-end encryption (Signal Protocol).
Functional Requirements
- •One-to-one instant messaging with delivery receipts (Sent, Delivered, Read)
- •Group chat with up to 1,024 members
- •Offline message storage and push notifications
Non-Functional Requirements
- •Sub-50ms message latency
- •End-to-End Encryption (E2EE)
- •Fault-tolerant message delivery with zero lost messages
Capacity & Scale Estimation
Core Architectural Components
1WebSocket Gateway Cluster
Maintains persistent bi-directional TLS WebSocket connections with active client apps.
2Session Service (Redis Cluster)
Maps UserID to Gateway ServerID so messages know exactly which socket server to route to.
3Distributed Message Queue (Kafka / RabbitMQ)
Decouples message ingestion from delivery workers, handling bursts and delivery retries.
4Offline Message Store (Cassandra)
Stores undelivered messages with TTL; messages are wiped the instant delivery is acknowledged.
Architectural FAQs & Interview Deep Dives
How does WhatsApp achieve End-to-End Encryption (E2EE)?
Using the Signal Protocol (Double Ratchet Algorithm + Prekeys). The server only forwards encrypted ciphertext; private decryption keys reside exclusively on user client devices.
How are group chat messages fanned out efficiently?
For small groups (e.g. <50), client-side fanout sends separate encrypted messages. For large groups, server-side fanout routes a single payload across recipient gateway nodes.