HARD
Design WhatsApp Messaging System
Design a real-time messaging application like WhatsApp supporting 1-on-1 chat, group chat, media sharing, and message delivery receipts.
Estimated Time: 45 minutes
#messaging#websockets#real-time#distributed
Solution Overview
WhatsApp architecture: WebSocket connections for real-time messaging, message queue for offline delivery, distributed database for message persistence, CDN for media files, push notification service, end-to-end encryption.
Hints to Get Started
1
Start with 1-on-1 messaging
2
Consider offline message delivery
3
How to handle read receipts?
Scalability Strategies
- •Shard by user_id
- •Message retention policy (30 days)
- •CDN for media
- •Redis for online presence
Components
- •WebSocket Gateway
- •Message Queue (Kafka)
- •User Session Manager
- •Message Store (Cassandra)
- •Media Storage (S3)
- •Push Notification Service
Message Flow
- •Client → WebSocket → Message Queue → Recipient WebSocket → ACK
- •If offline: Store in queue → Push notification → Deliver on reconnect
Database Design
messages
message_id, sender_id, recipient_id, content, timestamp, status
conversations
conversation_id, participants[], last_message, last_read