Home/Labs/WhatsApp Erlang Density
All 280 Labs
INTERACTIVE LAB💬

WhatsApp Erlang Connection Density Lab (Interactive)

Stack millions of persistent sockets per server and compare BEAM actors to OS threads. Compute RAM and TCP buffer ceilings for always-on messaging connections, and watch thread-per-connection designs hit a memory wall that Erlang's 2 KB processes shrug off.

WhatsApp BEAM Connection Density

Compare 1 MB OS-thread stacks against ~2 KB Erlang actors and tune FreeBSD TCP buffers to see how 50 engineers served 900M users.

Concurrent persistent sockets405.0M
Sockets per server (RAM + fd limits)2800K
Bare-metal messaging boxes needed145 servers
Total socket-buffer RAM1658.9 GB
Users per engineer (fleet of 50)18,000,000
~2.8M sockets per box: BEAM's 2 KB actors + 4 KB tuned buffers reproduce the WhatsApp density miracle.

Ephemeral pipeline: messages live in the in-flight queue only until the recipient's delivery ACK (double tick) purges them, so none of these servers carry chat-history storage.

How It Works Under the Hood

WhatsApp delivered 100 billion messages a day to two billion users with a few hundred engineers because its Erlang/OTP stack models each user session as a BEAM process of roughly 2 KB instead of a 1 MB operating-system thread. A server with 64 GB of RAM holds an order of magnitude more connections, and the true ceiling becomes the 4 KB per-socket TCP buffer and the file-descriptor limit near 2.8 million sockets per machine. Ephemeral routing state lives in RAM, so end-to-end encrypted message history is never persisted on servers.

Core Architectural Principles

  • BEAM actor memory: ~2 KB per session versus ~1 MB per OS thread — a 500x density advantage for long-lived connections.
  • Per-socket cost floor: 4 KB TCP read and write buffers plus the fd table cap total socket density at roughly 2.8 million per server.
  • Supervision trees restart crashed processes in milliseconds, so fault isolation is a runtime primitive, not an ops ritual.
Interview Round Script

When designing chat back ends, price the connection before the message: "One million persistent WebSockets at 4 KB buffers is 4 GB — one Erlang-style box, not a rack." Cite WhatsApp to justify actor-model servers, and mention that ephemeral routing keeps end-to-end encryption honest because nothing to leak is stored.

Key Trade-Offs

The BEAM buys extreme connection density and fault isolation but holds routing state in RAM and gives up shared-memory data structures that thread pools rely on.

Related Curriculum Chapter

WhatsApp: Extreme Efficiency with Erlang/OTP at Massive Scale

Read Full Chapter Blueprint

Explore More Interactive Labs

View All 280 Labs