Product, Scale, and Requirements
Understand WhatsApp's core product requirements, verified operational scale of 100 billion daily messages, and the hardware tuning that allowed 2 million concurrent connections per node.
In 30 seconds: WhatsApp connects over 2 billion active users handling 100 billion messages daily with an engineering team historically tiny compared to peers. Its foundational design decisions: Erlang BEAM processes on tuned FreeBSD, persistent bidirectional TCP connections, and an ephemeral zero-retention storage policy where messages vanish from server disks the moment they are acknowledged.
01The Hook: What Happens When You Tap Send
You tap Send on your phone, and a subtle clock icon instantly transforms into a single grey tick. A heartbeat later, that single tick becomes a double grey tick. Across town, or perhaps across an ocean, your friend Bob glances at his lock screen as a notification illuminates his display. When Bob unlocks his device and taps into your conversation, both grey ticks turn bright blue.
Throughout this seamless interaction, neither you nor Bob waited for an email-style refresh, experienced a spinning loader, or noticed any perceptible lag. Even more astonishing is the scale at which this choreography repeats: more than one million times every single second of the day, continuing without pause across every continent, time zone, and mobile carrier.
How does a system achieve sub-second delivery for billions of people without drowning under massive server costs, catastrophic memory leaks, or cascading gateway crashes? To understand the engineering triumph of WhatsApp, we must examine both the verified public facts of how its early team solved connection density and our structured engineering framework for designing a global real-time chat platform from first principles.
Throughout this entire case study module, we will follow a concrete running example: Alice (+1-555-0101) sending message msg-401 to her friend Bob (+1-555-0102), alongside their participation in a family group chat called #family-chat (grp-98).
Figure 1: Core throughput numbers, concurrent socket metrics, and operational invariants governing global chat delivery.
02Part 1: Verified Public Facts
Before making design assumptions, we examine what the creators and operators of WhatsApp have placed on public record through engineering talks, whitepapers, and operational retrospectives.
The Team and the Tech Stack
In 2014, when Facebook acquired WhatsApp for approximately 19 billion dollars, the entire company employed only 55 people, of whom 32 were software engineers. Those 32 engineers supported 450 million active users. This ratio of roughly 14 million users per engineer remains one of the highest leverage operational achievements in the history of internet computing.
The core technology choices behind this operational efficiency were deliberate:
- Erlang and the BEAM Virtual Machine: WhatsApp chose Erlang, a functional language designed by Ericsson in the late 1980s for telephone switching networks. Erlang runs on the BEAM virtual machine, providing lightweight concurrency, actor-based process isolation, and asynchronous message passing without shared memory locks.
- A Forked ejabberd Core: The initial gateway was built on
ejabberd, an open-source XMPP (Extensible Messaging and Presence Protocol) server written in Erlang. The WhatsApp team heavily modified this base, stripping away heavy XML protocol overhead in favor of a lean, custom binary protocol named FunXMPP. - FreeBSD as the Host Operating System: Rather than standard Linux distributions of that era, WhatsApp ran on FreeBSD on bare-metal servers. FreeBSD offered robust networking subsystems, mature
kqueueevent notifications, and kernel memory controls that allowed deep tuning of network buffers. - Mnesia and Transient Storage: User connection states and ephemeral routing tables were backed by Mnesia, Erlang's distributed embedded database, paired with custom disk queues.
The 2 Million Connection Milestone
In a landmark technical presentation at the Erlang Factory conference in 2012, WhatsApp software engineer Rick Reed revealed how the team pushed a single physical server node past 2 million concurrent established TCP connections. They subsequently achieved 2.8 million connections on a single box with 24 physical CPU cores and 100 gigabytes of RAM.
At the time, typical web servers built on Apache or standard Linux event loops struggled to maintain 50,000 to 100,000 concurrent sockets before memory exhaustion or CPU thrashing collapsed the node. WhatsApp overcame this barrier through systematic optimization across both the operating system kernel and the Erlang runtime:
- Socket Buffer Shrinking: Standard OS defaults allocate 64 kilobytes to 128 kilobytes of buffer memory per TCP connection for receive and transmit queues. Multiplying 64 kilobytes by 2 million sockets yields 128 gigabytes of RAM just for idle network buffers. WhatsApp tuned the kernel
sysctlparameters to reduce idle socket buffers down to approximately 4 kilobytes, dynamically expanding buffers only when active data was in flight. - Microscopic Actor Footprint: Each connected user was represented inside the BEAM runtime by an Erlang process. In Erlang, a process is not an operating system thread; it is a user-space actor managed entirely by BEAM. In Erlang R14B, a newly spawned process required only 309 words of memory (roughly 2.5 kilobytes on a 64-bit machine). Two million connected actors consumed approximately 5 gigabytes of heap memory.
- Kernel Hash Table Tuning: WhatsApp tuned FreeBSD kernel data structures (
kern.ipc.maxsockets,net.inet.tcp.tcbhashsize) to ensure socket lookups operated in constant time O(1) without bucket collisions under heavy load.
Figure 2: Architectural comparison between traditional thread-per-socket servers and WhatsApp's tuned FreeBSD plus Erlang BEAM runtime.
Public Operational Numbers
Modern public disclosures from Meta and WhatsApp provide verified boundary conditions for our system design:
- Monthly Active Users: Greater than 2 billion users globally.
- Daily Active Users: Estimated at over 1.2 billion users worldwide.
- Daily Message Volume: Publicly announced by Mark Zuckerberg in late 2020 as surpassing 100 billion messages per day (and growing).
- Peak Event Surges: On New Year's Eve, message throughput frequently surges by 50% to 100% over typical daily averages within specific regional midnight windows.
- Zero Disk Retention Invariant: WhatsApp publicly states that delivered messages are deleted from company servers immediately upon receiving a delivery receipt from the recipient device. If a message cannot be delivered immediately (for example, if Bob's phone is switched off), it is held transiently in an encrypted queue for up to 30 days before being discarded.
- End-to-End Encryption: Since 2016, WhatsApp has secured all one-to-one messages, group messages, voice calls, and media using the open-source Signal Protocol, co-developed with Open Whisper Systems. Server infrastructure routes only encrypted ciphertext blobs and cannot view message contents or decrypt media files.
03Part 2: Our System Design
Having established verified public facts, we now formalize how we would architect a global real-time messaging system to satisfy these operational realities.
Functional Requirements
To establish a clear scope for our design, we define four core functional capabilities:
- One-to-One Instant Messaging: Alice can send an encrypted text message
msg-401to Bob. Bob receives the message with low latency whenever his device is online. - Delivery Status Receipts: The system must provide deterministic status tracking for every message:
- Clock icon: Message stored locally on sender device, awaiting network socket dispatch.
- Single grey tick: Message received and acknowledged by server edge gateway.
- Double grey tick: Message delivered and acknowledged by recipient device.
- Double blue tick: Message marked as read or viewed by recipient in chat viewport.
- Presence and Activity Indicators: Users can see when a contact is currently online and view typing indicators ("Bob is typing...") inside active chat conversations.
- Group Conversations: Users can create group chats with up to 1,024 members. Any message sent to the group must be delivered to all active participants with end-to-end encryption.
- Multimedia Sharing: Users can send photos, audio notes, and videos. Media uploads must be decoupled from chat socket queues to prevent large payloads from blocking text delivery.
Non-Functional Requirements
The platform must satisfy rigorous operational and availability constraints:
- Sub-Second Latency: P99 message transit latency must remain under 500 milliseconds across mobile carrier connections globally when both endpoints are online.
- High Availability: Core messaging must maintain 99.99% availability (less than 53 minutes of unplanned downtime per year).
- Guaranteed At-Least-Once Delivery: The server must ensure no message is dropped in flight. Combined with client-side deduplication IDs, this guarantees exactly-once processing on the user's screen.
- Zero Persistent Server Footprint: Delivered messages must never be written to long-term database storage. Transient spooling for offline devices must enforce an automated 30-day time-to-live ceiling.
- Strict End-to-End Privacy: The server operates as a zero-knowledge relay. Keys are negotiated directly between user devices using the Signal Protocol; edge servers inspect only routing headers.
+-----------------------------------------------------------------------------------+
| System Requirements Summary |
+--------------------------+--------------------------------------------------------+
| Functional | Non-Functional |
+--------------------------+--------------------------------------------------------+
| 1. One-to-one text chat | 1. P99 latency < 500 ms worldwide |
| 2. Four-state receipts | 2. 99.99% edge availability |
| 3. Real-time presence | 3. Zero server message storage post-delivery |
| 4. Groups up to 1,024 | 4. End-to-end encryption (Signal Protocol) |
| 5. Ephemeral media store | 5. 30-day offline spooling ceiling |
+--------------------------+--------------------------------------------------------+04Part 3: Back-of-the-Envelope Estimation
Quantifying throughput, concurrency, memory, and bandwidth requirements grounds our architectural decisions in concrete engineering limits.
Throughput Calculations
We base our math on 100 billion messages per day across the global platform.
- Total Seconds per Day: 86,400 seconds (approximately 100,000 seconds).
- Average Messaging Throughput: Average QPS = 100 billion / 86,400 seconds = approximately 1,157,000 messages per second.
- Peak Multiplier: Messaging traffic exhibits daily regional peaks and holiday spikes. Applying a conservative peak factor of 2.5x: Peak QPS = 1.16 million * 2.5 = approximately 2,900,000 messages per second.
The system must handle approximately 1.16 million incoming messages per second on average, surging to nearly 3 million messages per second during peak events.
Connection Concurrency
To calculate the number of simultaneous open connections:
- Assume 2 billion registered users, with 25% of users maintaining an active long-lived TCP socket at any given moment during peak global daylight hours: Concurrent Open Sockets = 2 billion * 0.25 = 500,000,000 connections.
- If each tuned server node supports 1 million active connections with safe headroom (conservatively below Rick Reed's 2 million test limit): Edge Gateway Nodes Required = 500,000,000 / 1,000,000 = 500 physical server nodes.
A fleet of only 500 well-tuned gateway machines can maintain persistent TCP connections for half a billion concurrent devices.
Memory per Node Estimation
Each connected socket consumes memory across the operating system kernel and application user space:
- OS TCP socket control blocks and buffers: approximately 4 KB
- Erlang BEAM connection actor heap and mailbox: approximately 3 KB
- TLS session state: approximately 3 KB
- Total memory per connection: approximately 4 KB + 3 KB + 3 KB = 10 KB
- For 1 million connections per server node: Total Memory per Node = 1,000,000 * 10 KB = approximately 10 GB of RAM.
A modern enterprise server configured with 64 GB or 128 GB of RAM has abundant headroom to manage 1 million connected devices while retaining memory for burst message queues and routing caches.
Bandwidth Estimation
Text messages in a modern encrypted protocol are compact:
- Typical payload: approximately 200 bytes of encrypted ciphertext plus 100 bytes of protocol framing and routing metadata = 300 bytes per message.
- Ingress text bandwidth (Average): 1.16 million msgs/sec * 300 bytes = approximately 348 MB/sec (2.78 Gbps).
- Ingress text bandwidth (Peak): 2.9 million msgs/sec * 300 bytes = approximately 870 MB/sec (6.96 Gbps).
Even at global scale, text message payloads generate less than 7 Gbps of raw ingress traffic across the entire worldwide edge. Bandwidth is dominated not by text, but by media attachments (photos, voice notes, video), which we isolate onto an asynchronous content delivery network.
+-----------------------------------------------------------------------------------+
| Capacity & Scale Estimation |
+------------------------------+--------------------+-------------------------------+
| Metric | Average Value | Peak Value |
+------------------------------+--------------------+-------------------------------+
| Daily Message Volume | 100 Billion | 200 Billion (New Year's Eve) |
| Messaging Throughput (QPS) | ~1.16 Million/sec | ~2.9 Million/sec |
| Active Concurrent Sockets | 300 Million | 500 Million |
| Sockets Per Tuned Host | 1,000,000 | 1,500,000 |
| Total Gateway Nodes Needed | 300 - 500 hosts | 500 - 700 hosts |
| Memory Footprint per Socket | ~10 KB | ~12 KB |
| Global Text Ingress Rate | ~2.8 Gbps | ~7.0 Gbps |
+------------------------------+--------------------+-------------------------------+05Part 4: The Core Architectural Tension
Every distributed system is defined by the primary tension it resolves. In WhatsApp, that tension sits between instant real-time reachability and mobile network instability.
Mobile phones are hostile environments for distributed systems. Unlike servers housed in pristine data centers with redundant fiber connections, mobile devices constantly traverse cellular towers, switch between Wi-Fi and 5G networks, enter subway tunnels with zero reception, and face aggressive operating system battery-saving task killers.
+-----------------------------------------------------------------------------------+
| The Core Architectural Tension |
| |
| Target: Instant Delivery Reality: Fragile Edge Clients |
| - Sub-second P99 transit - Flapping cell tower handoffs |
| - Two-way push without polling - Silent socket termination by OS |
| - Zero-knowledge encryption - Severely limited battery & data |
+-----------------------------------------------------------------------------------+If the server assumed a client was always online, millions of messages would be pushed into dead TCP sockets and lost. Conversely, if the client repeatedly polled the server via standard HTTP requests (GET /messages), half a billion devices making requests every few seconds would generate hundreds of billions of HTTP requests per minute. This would flood cell networks and drain user batteries within hours.
WhatsApp resolved this tension through three architectural commitments:
- Persistent Bidirectional TLS Pipes: The client establishes a single, lightweight TCP connection over TLS to an edge gateway. This connection remains open indefinitely, kept alive by low-frequency ping packets (heartbeats sent once every few minutes).
- Deterministic State Machine on Both Ends: Every message follows an explicit sequence of acknowledgments (
PENDINGon sender device ->SENTto server ->DELIVEREDto recipient ->READby user). If a socket drops midway through this progression, both client and server can reconcile their exact state upon reconnection. - Decoupled Offline Buffering: When a recipient's connection is absent or broken, messages are redirected into an ephemeral offline spool. When the recipient reconnects, pending messages are streamed in chronological batches and purged from the server as soon as the client acknowledges receipt.
06Part 5: Component Overview and Invariants
To achieve these goals, our high-level architecture separates stateless connection handling from stateful session coordination:
[ Alice Mobile Client ]
|
| TLS / Custom Framing
v
[ Layer 4 Load Balancer (BGP / ECMP) ]
|
v
[ Chat Edge Gateway (Erlang BEAM Nodes) ] <---> [ Distributed Session Registry (DHT) ]
| |
+--------------------------+---------------------------+
|
+-----------------------+-----------------------+
| |
(Recipient Online) (Recipient Offline)
| |
v v
[ Chat Gateway (Bob's Node) ] [ Ephemeral Spool Buffer ]
| |
v v
[ Bob Mobile Client ] [ APNs / FCM Push Wake-Up ]The Architectural Invariants
Throughout this case study, we enforce four strict architectural invariants:
- The Server Never Possesses Plaintext: The edge gateway parses only message metadata (sender ID, recipient ID, message ID, timestamp, and client encryption parameters). The message body is an opaque byte array that only Bob's device possesses the cryptographic keys to decipher.
- Ephemeral Server Lifetime: The server cluster is an intelligent packet router, not an archive. As soon as Bob's device returns a delivery receipt, the message record is erased from memory and disk queues.
- Sender-Assigned Identifiers: Message IDs (
msg-401) are generated on the client device using UUIDs or cryptographically secure pseudorandom numbers prior to transmission. This ensures that network retries are inherently idempotent. - Separation of Control Plane and Data Plane: Real-time text messaging and presence updates flow over the dedicated chat socket. Bulky media uploads, contact synchronization, and profile picture downloads operate over standard HTTP/2 and HTTP/3 CDNs, preventing head-of-line blocking on the primary communication pipe.
Quiz · 4 questions
0 of 4 answered
1. Why did WhatsApp choose FreeBSD and Erlang BEAM over traditional Linux and Java thread-per-connection architectures in their early infrastructure?
2. What is the primary architectural invariant governing WhatsApp's server storage policy for delivered messages?
3. Why does WhatsApp avoid centralized Snowflake ID generators for assigning message IDs across 100 billion daily messages?
4. What is the primary factor limiting concurrency in a traditional thread-per-connection operating system model?
What you now know
You have analyzed the operational scale, verified hardware milestones, and core requirements of WhatsApp:
- How WhatsApp supports 2+ billion users and 100+ billion daily messages with an exceptionally compact engineering footprint.
- How Rick Reed and the early team tuned FreeBSD kernel socket buffers down to 4 kilobytes and used 2.5-kilobyte Erlang BEAM actors to achieve 2.8 million connections on a single machine.
- The distinction between verified public facts and our educational design assumptions.
- Why WhatsApp delegates chat history to the mobile client, eliminating petabytes of server database overhead.
In the next lesson, Architecture and Data Flow, we trace the journey of Alice's message msg-401 through Layer 4 load balancers, Erlang edge gateways, session routing tables, and the four-state delivery tick lifecycle.