Technologies Used in building WhatsApp Mobile Chat Application and WhatsApp-Web

WhatsApp’s architecture is a legendary case study in software engineering, famously scaling to billions of users with a remarkably small team (only about 50 engineers for its first 900 million users).

Here is the breakdown of the technologies and structures that make it tick.

🛠 Core Technology Stack

WhatsApp relies on a "pick the right tool for the job" philosophy, choosing technologies known for extreme concurrency and reliability over popular "hype" frameworks.

Backend & Server Side

  • Erlang (BEAM VM): The crown jewel of WhatsApp. Erlang was designed for telecom switches. It allows WhatsApp to handle millions of concurrent connections per server.

  • Ejabberd: A heavily modified version of this XMPP-based Jabber server is used for message routing and presence (online/offline status).

  • FreeBSD: Unlike most of Silicon Valley which uses Linux, WhatsApp uses FreeBSD as its OS because of its superior networking stack and performance under high load.

  • Mnesia: A distributed, soft real-time database management system written in Erlang. It stores session data, routing tables, and transient information.

Databases & Storage

  • RocksDB: Used as a high-performance, embedded key-value store for managing local data.

  • MySQL: Used for persistent user data (profiles and settings), often sharded across many servers.

  • SQLite: The local database on your phone that stores your chat history.

  • Amazon S3 / CDN: Stores multimedia (images, videos) temporarily until the recipient downloads them.

Messaging & Communication

  • Signal Protocol: The industry standard for End-to-End Encryption (E2EE).

  • WebRTC: Powers the high-quality voice and video calling.

  • Custom XMPP: A specialized, binary-encoded version of the Extensible Messaging and Presence Protocol to keep data packets as small as possible.

Project & Data Structure

WhatsApp is not a "cloud" app like Telegram; it is a "local-first" app. This affects how the project and folders are structured.

Mobile App Structure (Frontend)

WhatsApp uses native code for maximum performance rather than hybrid frameworks:

  • Android: Primarily Java and Kotlin.

  • iOS: Primarily Swift and Objective-C.

  • Web/Desktop: React and Electron (for the wrapper).

Client-Side Folder Structure (On-Device)

If you explore the file system on a mobile device, the data is organized to handle heavy media and encrypted backups:

  • /Databases: Contains msgstore.db.crypt14. This is your chat history, encrypted with a key tied to your account.

  • /Media: Sub-folders for .Statuses, WhatsApp Images, WhatsApp Voice Notes, and WhatsApp Video.

    • Note: Sent files are kept in a separate /Sent sub-folder to avoid duplication.

  • /Backups: Stores local configuration backups and sticker settings.

Messaging "Lifecycle" Structure

The logic flow for a message follows a very specific structural path:

  1. Client Layer: Encrypts the message using the recipient's public key.

  2. Connection Layer: Transmits via a persistent WebSocket to the server.

  3. Routing Layer (Erlang): The server identifies if the recipient is online.

  4. Transient Storage: If the recipient is offline, the message is stored in a temporary queue (usually for 30 days) and then deleted once delivered. WhatsApp does not store your messages on its servers permanently.

💡 Key Design Principles

  • Statelessness: Once a message is delivered, the server forgets it.

  • No "Bloat": They avoid heavy XML or JSON where possible, using custom binary formats to save every possible byte of user data.

  • Actor Model: Every single user connection is treated as an independent "actor" in Erlang, so if one user's connection crashes, it doesn't affect anyone else.

To wrap everything up, WhatsApp’s architecture is a masterclass in vertical scaling (making a single server do more) and minimalism.

While modern apps often use complex cloud-native microservices (hundreds of tiny services), WhatsApp stays lean, using a few high-performance tools to handle billions of users.

🏗 High-Level System Architecture

WhatsApp's system is designed to maintain a persistent connection between your phone and their servers. This is called a long-lived socket connection.

The Workflow of a Message:

  1. Encryption: Your app uses the Signal Protocol to lock the message.

  2. Transmission: The message is sent as a binary "stanza" (not bulky JSON) over a WebSocket.

  3. The Erlang Node: A server running FreeBSD and Erlang receives it. This server manages millions of other "actors" (user processes).

  4. Routing & Presence: The server checks Mnesia (an in-memory DB) to see if the recipient is online.

  5. Delivery:

    • Online: The message is pushed immediately.

    • Offline: The message is stored in a MySQL/RocksDB queue for up to 30 days. Once the recipient connects, the message is sent and then permanently deleted from the server.

  6. Multimedia: Images/Videos are uploaded to S3/CDN separately; only the encrypted link is sent in the chat.

📋 Summary of Technical Components

Category Technology Used Why?
Operating System FreeBSD Superior networking stack for handling 2M+ connections per server.
Backend Language Erlang (BEAM VM) Designed for 99.999% uptime and extreme concurrency.
Server Engine Ejabberd Modified XMPP server for routing billions of messages.
Web Server YAWS High-performance Erlang web server for the API layer.
Encryption Signal Protocol The gold standard for end-to-end privacy (E2EE).
In-Memory DB Mnesia Real-time session and routing data (built into Erlang).
Persistent DB MySQL / RocksDB Sharded storage for user profiles and offline message queues.
Mobile Database SQLite Efficient local storage of your chat history on your phone.

🎯 Key Takeaways for 2026

  • The "Let it Crash" Philosophy: WhatsApp doesn't try to prevent every error. If a user's process crashes, Erlang simply restarts it without affecting other users.

  • Binary over Text: They use a custom binary version of XMPP. This saves battery and data, which is why WhatsApp works so well on slow 2G/3G networks.

  • Privacy by Deletion: By not storing delivered messages, they reduce their database load significantly and enhance user trust.

  • Vertical Scaling: They prefer fewer, extremely powerful servers over thousands of small ones. This reduces "network hop" latency.

Final "Wrap-Up" Fact:

When Facebook (Meta) bought WhatsApp for $19 billion, the company had only 55 employees, and only 32 of them were engineers. That is the power of choosing a high-performance stack like Erlang and FreeBSD.

 

Code

To give you the complete picture, here is a breakdown of how you would structure a WhatsApp-style project and a guide to the system design logic that keeps it running at scale.

📂 Backend Project Structure (Erlang/OTP)

If you were to look at the source code for a WhatsApp-like backend, it wouldn't look like a standard Node.js or Python app. It follows the OTP (Open Telecom Platform) directory structure:

  • apps/: Contains the core logic.

    • messaging/: Logic for handling chat stanzas and delivery receipts.

    • presence/: Manages "Last Seen" and "Online" statuses using a distributed hash table.

    • gateway/: Handles the TCP/TLS connections from the mobile apps.

  • deps/: External libraries (like ejabberd modules or noise for encryption).

  • rel/: Release configurations for deploying the code to FreeBSD servers.

  • priv/: Private assets, such as SSL certificates and protocol buffer definitions.

🏗️ The System Design Blueprint

The magic of WhatsApp is in the "Hop" a message takes. It is designed to be asynchronous—meaning the sender doesn't wait for the receiver to be online to "finish" the task.

The 4-Step Message Lifecycle:

  1. The Handshake: When you open the app, it performs a Noise Protocol handshake (a lightweight version of TLS) to establish a secure pipe to the server.

  2. The Stanza: Your message is wrapped in a "Binary XMPP" packet. This reduces the size of a "Hello" message from ~500 bytes (JSON) to ~40 bytes.

  3. The Actor Mailbox: In the Erlang backend, every user is a "Process." The server puts your message in the recipient's "Mailbox."

  4. The ACK (Acknowledgment): * One Gray Tick: Message reached the server.

    • Two Gray Ticks: Message reached the recipient's device.

    • Blue Ticks: The recipient's app sent a "Read" receipt back through the pipe.

🛠️ Comparison: WhatsApp vs. Standard Apps

Feature Standard "Cloud" App WhatsApp Approach
Communication HTTP REST (Request/Response) Long-lived TCP Sockets (Always on)
Data Format JSON (Text-heavy) Binary XMPP (Compressed)
Storage Permanent Cloud Database Transient (Delete after delivery)
Scale Strategy Horizontal (Add 1,000s of small VMs) Vertical (Optimize 1 server for 2M+ users)

🏁 Wrapping Up

WhatsApp's success wasn't built on "fancy" new tools, but on battle-tested telecom tech. By using Erlang, they treated chat messages like phone calls—fast, ephemeral, and reliable.

They focused on:

  1. Low Latency: Using FreeBSD's kernel to handle massive amounts of data.

  2. Security: Implementing the Signal Protocol so even they cannot read your data.

  3. Efficiency: Writing code that runs on minimal RAM to save costs.

To wrap this deep dive up, let’s look at the "engine" under the hood. Erlang isn't like Java or Python; it uses the Actor Model, where every user is a tiny, isolated "process" that only communicates by sending messages.

Here is a look at the specific code logic and the advanced encryption that makes WhatsApp both scalable and private.

💻 The Erlang "Actor" (How a User Connection Works)

In a typical server, a crash might take down the whole system. In WhatsApp’s Erlang backend, if your connection glitters, only your process dies and restarts.

Erlang

%% A simplified version of a WhatsApp User Actor
-module(chat_user).
-export([start/1, loop/1]).

start(UserId) ->
    spawn(fun() -> loop(UserId) end).

loop(UserId) ->
    receive
        {send_message, RecipientId, Content} ->
            io:format("User ~p sending encrypted blob to ~p~n", [UserId, RecipientId]),
            % Logic to route to RecipientId's process
            loop(UserId);
        {receive_message, FromId, EncryptedBlob} ->
            io:format("User ~p received message from ~p~n", [UserId, FromId]),
            % Push to mobile device via socket
            loop(UserId)
    end.

🔐 The Signal Protocol: The "Double Ratchet"

WhatsApp uses the Double Ratchet Algorithm. It’s the reason why, even if someone hacked a server and stole a key today, they couldn't use it to read your messages from yesterday.

  • X3DH (Extended Triple Diffie-Hellman): Establishes a shared secret between two people who have never met.

  • The Ratchet: Every time you send a message, the encryption key "turns" (changes).

  • Perfect Forward Secrecy: Because the key constantly changes and old keys are deleted, the past remains locked forever.

🏗️ WhatsApp Project Structure (The "Big Picture")

If you were building this from scratch today, your project folder and system flow would look like this:

1. The Repository Structure

  • /client: Native iOS (Swift) and Android (Kotlin) codebases.

  • /common: Protocol Buffer (.proto) files that define the message structure for both mobile and server.

  • /server:

    • connector/: Manages millions of WebSocket/TCP connections.

    • router/: The Erlang logic that moves messages from A to B.

    • media_service/: A Go or Rust microservice to handle heavy image/video uploads to S3.

2. The Data Flow Summary

  1. App sends an encrypted binary packet.

  2. Server checks a cache (Redis/Mnesia) for the recipient's location.

  3. Server pushes the packet to the recipient’s active socket.

  4. Recipient app sends back a "Delivered" receipt.

  5. Server deletes the message from its RAM/Queue.

🏁 Final Wrap-Up

WhatsApp is the ultimate proof that engineering discipline beats "bloat." By sticking to a small team and a powerful, specialized language like Erlang, they achieved what companies with 10x the staff struggle to do.

Key Technical Summary:

  • Concurrency: Erlang/OTP.

  • Speed: FreeBSD & Binary XMPP.

  • Privacy: Signal Protocol (E2EE).

  • Philosophy: Don't store what you don't have to.

Select Chapter