🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Design WhatsApp

System Design ProblemsMessaging SystemsđŸŸĸ Free Lesson

Advertisement

System Design Problems

Design WhatsApp

WhatsApp serves 2B+ users with 100B+ messages daily. This design explores building a globally distributed messaging platform with end-to-end encryption, media delivery, and real-time presence.

  • Scale — 2B users, 100B messages/day, 50M messages/second peak
  • Latency — Message delivery under 100ms for 95% of messages
  • Encryption — End-to-end encryption using Signal Protocol

Designing for WhatsApp means solving the hardest problems in distributed messaging at planetary scale.

Requirements Clarification

Functional Requirements

  1. One-to-one text messaging with delivery/read receipts
  2. Group messaging (up to 1024 members)
  3. Media sharing (images, videos, documents up to 2GB)
  4. Online/offline presence indicators
  5. Message history and synchronization across devices
  6. End-to-end encryption (E2EE)

Non-Functional Requirements

  1. Availability: 99.99% uptime
  2. Latency: < 100ms for message delivery (P99)
  3. Durability: Messages must not be lost once sent
  4. Consistency: Causal ordering within conversations
  5. Scale: 2B registered users, 500M daily active users

Back-of-the-Envelope Estimation

High-Level Architecture

MobileWebDesktopLoad Balancer (L7)ConnectionManagerMessageRouterPresenceServiceMediaServiceGroupServiceMessage Queue (Kafka)Message Store(Cassandra)User DB(MySQL)Media Store(S3 + CDN)Presence Store(Redis Cluster)

Core Components Deep Dive

1. Connection Manager

Maintains persistent WebSocket connections with clients:

class ConnectionManager:
    def __init__(self):
        self.user_connections = {}  # user_id -> {device_id: server_id}
        self.server_connections = {}  # server_id -> {connection_id: user_id}
    
    def register(self, user_id, device_id, server_id):
        self.user_connections[user_id][device_id] = server_id
        self.server_connections[server_id][connection_id] = user_id
    
    def get_servers(self, user_id):
        return set(self.user_connections.get(user_id, {}).values())

2. Message Router

Routes messages between senders and receivers:

3. Message Flow (1:1 Chat)

Sender(Online)1. Send Message2. Store in Queue3. Persist to DB4. Deliver to ReceiverReceiver(Online/Offline)5. Delivery Receipt6. Read Receipt

4. End-to-End Encryption

5. Group Messaging

6. Presence System

Data Model

Scaling Strategies

Message Storage Partitioning

Messages are partitioned by chat_id using consistent hashing:

Push vs Pull for Delivery

Practice Exercises

  1. Design: How would you implement message synchronization across multiple devices for the same user? Consider ordering and conflict resolution.

  2. Scale: WhatsApp has 50M concurrent users. Estimate the number of WebSocket connections needed and the memory overhead per connection.

  3. Reliability: Design a mechanism to ensure messages are never lost, even if the sender's device crashes after sending but before receiving acknowledgment.

  4. Optimization: How would you reduce bandwidth usage for users on slow networks? Propose a compression strategy for text and media.


What to Learn Next

-> Design Instagram Photo sharing, feeds, and media delivery at scale.

-> Design Twitter Real-time feeds, fan-out, and timeline generation.

-> Design YouTube Video streaming, transcoding, and CDN delivery.

-> Design Netflix Content delivery, recommendation, and adaptive streaming.

-> Circuit Breaker Pattern Preventing cascade failures in distributed systems.

-> Back Pressure Managing load in message-driven architectures.

Need Expert System Design Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement