System Design Interview: Architecting WhatsApp for 10 Billion Daily Messages
WhatsApp handles billions of messages every day without crashing. In this system design interview scenario, we break down the architecture behind a scalable messaging system like WhatsApp, covering message queues, real-time communication, load balancers, database scaling, message storage, high availability, and support for millions of concurrent users.
Key Requirements
- Functional: Send/receive messages, support for group chats, message delivery status, and offline messages.
- Non-functional: High availability, low latency, scalability, and durability.
Estimation and Data Math
With 10 billion daily messages, we calculate:
- Messages per second (MPS): 10B / 86,400 ≈ 115,740 MPS.
- Expected growth: Doubling within a year, so plan for ~231,480 MPS.
- Storage per message: ~200 bytes.
- Daily storage: 10B × 200 bytes = 2 TB.
- Yearly storage: 2 TB × 365 × 2 ≈ 1.5 PB (accounting for growth).
Note that systems must handle peak traffic, which can be significantly higher than average MPS.
High-Level Architecture
- Load Balancers: Distribute incoming traffic across multiple servers.
- WebSocket Servers: Maintain persistent connections for real-time communication.
- Message Queues: Buffer messages for reliable delivery (e.g., Apache Kafka or RabbitMQ).
- Database Layer: Use a combination of SQL for metadata and NoSQL for message storage (e.g., Cassandra for high write throughput).
- Caching Layer: Redis for session management and real-time online status.
- CDN: For media files (images, videos).
Key Considerations
- Consistency vs. Availability: Prioritize availability and eventual consistency for messages.
- Data Partitioning: Shard databases by user ID or chat ID.
- Fault Tolerance: Replicate data across data centers.
- Security: End-to-end encryption (already implemented by WhatsApp).
This high-level overview provides a starting point for a system design interview. For deeper dives, explore specific components like message storage, real-time delivery, or database scaling.