⬅ Previous Topic
Design Instagram - System Design Tutorial for BeginnersNext Topic ⮕
System Design: How to Design YouTube⬅ Previous Topic
Design Instagram - System Design Tutorial for BeginnersNext Topic ⮕
System Design: How to Design YouTubeIn this module, we will learn how to design WhatsApp — a real-time, scalable, fault-tolerant messaging platform. WhatsApp is used by billions to send and receive instant messages, images, and voice notes. Designing such a system requires careful attention to latency, consistency, and scalability.
WhatsApp uses a mobile-first approach where the client (mobile app) maintains a persistent connection with the backend using a protocol like XMPP or custom WebSockets over TCP. This enables instant message delivery.
When User A sends a message to User B:
How can we ensure User B receives the message even if their phone is off?
We use a Message Queue to store undelivered messages. When User B reconnects, the server pushes the queued messages to the client.
Messages are stored temporarily in a distributed message queue (e.g., Kafka or RabbitMQ). Once a message is delivered and acknowledged, it can be deleted or archived.
Different microservices handle different tasks — message service, media service, notification service, etc. We scale each service independently based on traffic.
To handle billions of messages, we shard the message storage by user ID or region to distribute load across databases.
WhatsApp supports image, video, document sharing. Media files are not sent directly through the messaging queue. Instead, they are uploaded to cloud storage (e.g., Amazon S3), and a download link is sent through the message.
User A sends a video:
WhatsApp shows three status levels for messages: Sent ✓, Delivered ✓✓, and Read ✓✓ in blue. Each transition is acknowledged back to the sender:
What if the recipient is offline?
The server will hold the message and status updates until the recipient comes online and acknowledges it.
WhatsApp uses the Signal Protocol for end-to-end encryption. Each message is encrypted on the sender’s device and decrypted only on the receiver’s device.
Group chats are trickier as messages must be delivered to multiple recipients.
Store message once and reference it in each user's inbox to reduce duplication.
When users are offline, messages are queued, and the server sends push notifications via FCM/APNs. Upon reconnect, the app syncs new messages.
Monitor systems using tools like Prometheus, Grafana, and Sentry for real-time alerts and performance tracking. Deploy failover systems and replication to ensure high availability.
Designing WhatsApp involves balancing real-time delivery, storage efficiency, reliability, and encryption. By splitting the architecture into microservices and separating message content from media, we can design a scalable and robust system.
⬅ Previous Topic
Design Instagram - System Design Tutorial for BeginnersNext Topic ⮕
System Design: How to Design YouTubeYou can support this website with a contribution of your choice.
When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.