High-Level Design (HLD) of WhatsApp

Introduction to High-Level System Design

1. About the System

WhatsApp is a global messaging platform that facilitates real-time communication through text, images, videos, voice notes, and calls. It is designed to be:

  • Highly Scalable: Supports billions of users.
  • Real-Time: Messages delivered instantly.
  • Highly Available: Minimal downtime.
  • Secure: End-to-end encryption ensures privacy.
High-Level Design (HLD) of WhatsApp - visual selection

2. Requirements & Goals

Functional Requirements

  • User Management: Signup, login, profile updates, and contact management.
  • Messaging: Send/receive text, images, videos, and files.
  • Real-time Communication: Implemented using WebSockets.
  • Group Chats: Users can create and participate in group conversations.
  • Voice/Video Calls: Supports one-on-one and group calls.
  • Status Updates: Users can post text, images, and videos.
  • Notifications: Push and in-app notifications.
  • Security: End-to-end encryption for messages and calls.
Requirements & Goals

Non-Functional Requirements

  • Scalability: Supports billions of messages daily.
  • Low Latency: Instant message delivery.
  • High Availability: 24/7 uptime.
  • Data Consistency: Message ordering must be maintained.
  • Efficient Storage: Optimized storage for messages and media.
2. Requirements & Goals - visual selection (1)

3. Capacity Estimations and Constraints

Assumptions

  • Daily Active Users (DAU): 50 million
  • Messages per User per Day: 20
  • Total Messages per Day: 50M × 20 = 1B
  • Media Messages: 5% of total messages (50M)
  • Average Message Size: 100 bytes for text, 100 KB for media
  • Storage Needs:
    • Text: 950M × 100B = ~95GB/day
    • Media: 50M × 100KB = ~5TB/day
    • Total Storage per Day: ~5.1TB
    • 5-Year Projection: ~9.3PB
  • Bandwidth: ~120 MB/sec
  • Requests per Second (RPS): ~24K

4. System APIs

Authentication

  • POST /api/login: Authenticate user and return session token.
  • POST /api/logout: Logout user.

Messaging

  • POST /api/messages: Send a message.
  • GET /api/messages: Retrieve messages for a user.

Group Chats

  • POST /api/groups: Create a group.
  • POST /api/groups/add: Add user to a group.
  • POST /api/groups/messages: Send a group message.

Voice/Video Calls

  • POST /api/calls/start: Start a call.
  • POST /api/calls/end: End a call.

Status Updates

  • POST /api/status: Post status update.
  • GET /api/status: Retrieve status updates.

Notifications

  • POST /api/notifications: Send push notifications.

5. Data Model Design

Tables

  • Users: Stores user information.
  • Messages: Stores messages with type, content, and timestamps.
  • Chats: Represents private chats between users.
  • Users_Chats: Maps users and chats (N:M relationship).
  • Groups: Stores group details.
  • Users_Groups: Maps users and groups (N:M relationship).

Database Choice

  • Relational Databases (PostgreSQL): For structured data (users, chats, groups).
  • NoSQL (Cassandra, DynamoDB): For messages to ensure scalability.

6. API Design

Get All Chats or Groups

getAll(userID: UUID): Chat[] | Group[]

Get Messages

getMessages(userID: UUID, channelID: UUID): Message[]

Send Message

sendMessage(userID: UUID, channelID: UUID, message: Message): boolean

Join/Leave Group

joinGroup(userID: UUID, channelID: UUID): boolean

leaveGroup(userID: UUID, channelID: UUID): boolean

7. High-Level Architecture

Microservices-Based Architecture

Core Services:

  1. User Service: Manages user authentication and profile information.
  2. Chat Service: Handles real-time messaging via WebSockets.
  3. Notification Service: Sends push notifications.
  4. Presence Service: Tracks online status.
  5. Media Service: Handles media uploads and storage.

Inter-Service Communication

  • REST API & gRPC for synchronous calls.
  • Message Queue (Kafka/RabbitMQ) for asynchronous processing.

8. Scaling and Optimization Strategies

Horizontal Scaling

  • Load Balancers (NGINX, HAProxy) distribute traffic.
  • Multiple database shards to handle storage efficiently.

Caching

  • Redis/Memcached for frequently accessed data (user profiles, messages).

Data Storage Strategy

  • Cold Storage: Older messages archived to reduce database load.
  • CDN: Distributes media content for reduced latency.

9. Security Considerations

  • End-to-End Encryption (E2EE): Ensures message confidentiality.
  • OAuth & Token-Based Authentication: Secures API access.
  • Rate Limiting & Throttling: Prevents spam attacks.

10. Conclusion

This HLD provides a structured approach to designing WhatsApp’s architecture, ensuring scalability, high availability, and robust security measures.

DSA, High & Low Level System Designs

Buy for 60% OFF
₹25,000.00 ₹9,999.00

Accelerate your Path to a Product based Career

Boost your career or get hired at top product-based companies by joining our expertly crafted courses. Gain practical skills and real-world knowledge to help you succeed.

Reach Out Now

If you have any queries, please fill out this form. We will surely reach out to you.

Contact Email

Reach us at the following email address.

arun@getsdeready.com

Phone Number

You can reach us by phone as well.

+91-97737 28034

Our Location

Rohini, Sector-3, Delhi-110085

WhatsApp Icon

Master Your Interviews with Our Free Roadmap!

Hi Instagram Fam!
Get a FREE Cheat Sheet on System Design.

Hi LinkedIn Fam!
Get a FREE Cheat Sheet on System Design

Loved Our YouTube Videos? Get a FREE Cheat Sheet on System Design.