Real-Time & Messaging

Designing a Real-Time Chat & Messaging Platform (WhatsApp / Discord)

Staff / Lead

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).

Production Scale: 2.5 Billion Users • 100 Billion Messages/Day • 50M Concurrent Conns

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

Active WebSocket Connections50,000,000 concurrent sockets
Daily Messages100 Billion msgs/day (~1.15M msgs/sec)
Peak Throughput3.5 Million msgs/sec during events
Message StorageEphemeral (Deleted from server once delivered to client)

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.