system-architecture

Understanding WhatsApp’s Architecture & System Design

Sandeep Reddy

May 1, 2024
Understanding WhatsApp’s Architecture & System Design

WhatsApp: The World’s Most Popular Messaging App

Which app has over 2.5 billion active users, more than 5 billion downloads, and reigns as the most popular app in over 100 countries?

Yes, that’s right—WhatsApp is the most popular messaging service in the world. According to Mark Zuckerberg, over 100 billion messages are sent over WhatsApp every day.

With such mind-boggling traffic, one can’t help but wonder: How does WhatsApp manage it all? How does it handle so many concurrent users and messages? What kind of system design, server architecture, and technologies power this behemoth? And most importantly, how do they keep all that data secure?

In this article, we’re going to take a deep dive into WhatsApp’s architecture and system design. We’ll explore everything from the front-end tech stack to the backend hardware that keeps it all running smoothly. If you’ve ever wondered what makes the top dog in the chat app world tick, keep reading.

WhatsApp Front-End Tech Stack

Let’s kick things off with the front end—the part of WhatsApp that you, as a user, interact with on your device. Whether you’re chatting on your smartphone, sending a voice note on your desktop, or checking messages on the web, the frontend is where it all begins.

Interestingly, despite supporting a wide array of platforms, WhatsApp isn’t a hybrid app. Instead, they opted for native development on each platform to ensure optimal performance and user experience. Here’s a breakdown of the languages used for each supported platform:

  • Android: Java
  • iOS: Swift
  • Windows Phone: C#
  • Web app: JavaScript/HTML/CSS
  • Mac Desktop app: Swift/Objective-C
  • PC Desktop app: C/C#/Java

Each of these languages was chosen to leverage the strengths and capabilities of the platform it runs on, ensuring that WhatsApp delivers a seamless experience, regardless of the device.

The image you provided depicts a simplified version of the WhatsApp architecture. Let’s break it down:

1. Mobile Users:

— Represents individual devices (smartphones) that people use to access WhatsApp.
— Each mobile device has a local SQLite DB where user data and messages are stored.

2. Communication Protocols:

— Devices connect using both the HTTP and XMPP (Extensible Messaging and Presence Protocol) protocols. HTTP is commonly used for web services, while XMPP is tailored for real-time chat applications.

3. YAWS Server:

— This is the server that handles web requests, specifically those made using HTTP.

4. Custom ejabberd Server Cluster:

— Represents the core server cluster of WhatsApp, which manages message routing and user presence. It is custom-built on the ejabberd framework, a robust XMPP server.

5. Media Data:

— This component handles multimedia messages, like photos, videos, and voice notes. The diagram suggests a flow where media is processed differently from text messages.

6. Media Store CDN:

— Content Delivery Network (CDN) for media storage. CDNs are distributed systems that deliver content based on the user’s geographic location to ensure fast and efficient access.

7. Databases:

  • Mnesia DB Cluster: A distributed database management system integrated with the Erlang runtime, ideal for handling fault-tolerant and high-availability applications.
  • MySQL/PostgreSQL: Relational database systems well-suited for storing and managing structured data.
  • Riak: A distributed NoSQL database designed for high-performance, high-availability, and scalability in applications with heavy data traffic.

8. GCM/APNs:

  • Push Notification Systems: GCM (Google Cloud Messaging), now known as Firebase Cloud Messaging (FCM), is used for delivering push notifications to Android devices. APNs (Apple Push Notification Service) serves the same purpose for iOS devices.

9. Offline Users:

— A component to represent users who are not currently online or active. The architecture likely ensures that messages meant for offline users are stored and delivered once they come online.

10. Write-only:

— This indicates certain data operations where data can be written to the storage but not read or modified. It ensures data integrity and security for specific operations.

From this diagram, you can glean that WhatsApp has a distributed architecture with a mix of relational and NoSQL databases, specialized servers for handling messaging, media storage solutions, and integrations with platform-specific push notification services. The separation of components ensures scalability and performance for a massive user base.

Here’s a textual representation of how you might structure it:

1. Top Layer (User Interfaces):
— Mobile Clients (Android, iOS, etc.)
— Web Client (WhatsApp Web)

2. Communication Layer:
— WebSockets (for real-time bidirectional communication with the web client)
— XMPP Protocol (or its modified version for mobile clients)

3. Application Servers:
— Erlang-based Servers (handling requests, routing messages)
— YAWS (handling web requests)

4. Security Layer:
— End-to-end Encryption (using the Signal Protocol)
— Rate Limiting Mechanisms

5. Data Management and Storage:
— SQLite (Local database on mobile clients)
— RocksDB (Server-side storage)
— Multimedia Files Storage (links to Google Drive and iCloud for backups)

6. Supporting Services:
— Notifications (using APNs for iOS and FCM for Android)
— Puppeteer (for web application testing)
— Traffic Management (Load balancers)

7. Infrastructure:
— FreeBSD (Operating system on servers)
— Geo-redundant Data Centers

Certainly! Let’s delve deeper into each aspect of WhatsApp’s architecture:

1. Client-Server Model:
— In this model, client devices (like smartphones) request services, and servers provide them. WhatsApp clients send messages to the server, which then routes the messages to the intended recipients. This structure enables centralized management and facilitates scalability.

2. Erlang:
— Developed by Ericsson, Erlang is a functional, concurrent programming language and runtime system. Its strength lies in building scalable and maintainable applications, making it perfect for a service like WhatsApp that needs high concurrency.

3. YAWS (Yet Another Web Server):
— YAWS outperforms many other web servers in terms of concurrent connections, making it apt for services that anticipate numerous simultaneous connections. YAWS also integrates seamlessly with Erlang-based applications.

4. FreeBSD:
— An advanced OS for modern server, desktop, and embedded platforms. WhatsApp chose FreeBSD for its performance and advanced networking features. It’s known for its reliability and robustness.

5. Ejabberd XMPP Server:
— This is a robust and scalable XMPP server. XMPP is a communication protocol for message-oriented middleware. While WhatsApp started with XMPP, they’ve made significant modifications for performance enhancements.

6. End-to-end Encryption:
— This ensures that only the sender and the intended recipient can read a message. Even if intercepted during transmission, the content remains encrypted and unreadable. The Signal Protocol achieves this through a combination of asymmetric and symmetric cryptography.

7. Multimedia Files Storage:
— WhatsApp’s decision to use cloud backups (like Google Drive and iCloud) was mainly for user convenience, allowing users to restore their messages and media when switching devices.

8. WebSockets:
— Unlike the traditional request-response model, WebSockets allow servers to push information to clients. This technology is instrumental for real-time applications like WhatsApp Web, ensuring that messages are delivered instantly.

9. Databases:
— 
SQLite: A C-language library that provides a lightweight disk-based database. It doesn’t require a separate server process. Ideal for mobile apps like WhatsApp.
— 
RocksDB: Developed by Facebook, it’s an embeddable persistent key-value store. It’s optimized for fast storage with a focus on SSDs and in-memory build-ups.

10. Puppeteer:
— Developed by Chrome’s team, Puppeteer is a node library offering a high-level API to control headless Chrome browsers. This aids in automating tasks within the browser, crucial for testing web applications.

11. Geo-redundancy:
— By having data centers in multiple locations, WhatsApp ensures that if one center faces issues, another can take over, guaranteeing uninterrupted service.

12. Traffic Management:
— With billions of messages daily, traffic management tools ensure efficient data routing, minimizing lags or downtimes.

13. Rate Limiting:
— By imposing limits on the number of requests from a user in a specific time frame, WhatsApp prevents system overloads and misuse.

14. Notifications:
— Services like APNs (for iOS) and FCM (for Android) are crucial for notifying users of new messages, especially when the app isn’t open.

15. Data Compression:
— Data compression reduces the amount of data sent over the network, ensuring quicker message deliveries and reduced data consumption for users.

While this goes into more depth, it’s important to note that the intricacies of WhatsApp’s architecture and its proprietary modifications aren’t fully disclosed to the public. This overview provides a foundational understanding based on the available information.

Related Posts

Schedule a meeting to take your business to the next level.

    Get a Quote