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.
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.
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.
Start with 1-on-1 messaging
Consider offline message delivery
How to handle read receipts?
- •Shard by user_id
- •Message retention policy (30 days)
- •CDN for media
- •Redis for online presence
- •WebSocket Gateway
- •Message Queue (Kafka)
- •User Session Manager
- •Message Store (Cassandra)
- •Media Storage (S3)
- •Push Notification Service
- •Client → WebSocket → Message Queue → Recipient WebSocket → ACK
- •If offline: Store in queue → Push notification → Deliver on reconnect
messages
message_id, sender_id, recipient_id, content, timestamp, status
conversations
conversation_id, participants[], last_message, last_read