DEV Community

Cover image for How WhatsApp Scaled to 450M Users Using Erlang
Doogal Simpson
Doogal Simpson

Posted on Originally published at doogal.dev

How WhatsApp Scaled to 450M Users Using Erlang

Quick Answer: WhatsApp supported 450 million active users with just 32 engineers by running on Erlang. Erlang allocates tiny, user-space virtual machine processes that require only 2.6 kilobytes of memory per connection, compared to roughly 1 megabyte per thread in traditional environments like Java. This runtime efficiency allowed single servers to handle millions of persistent sockets simultaneously.

Imagine running an on-call rotation where every single engineer on your team is personally responsible for 14 million active users. Back in 2014, when Facebook acquired WhatsApp for $19 billion, that was the exact reality for their 32-person engineering team.

Keeping a global messaging platform online at that scale sounds like a nightmare that would demand hundreds of engineers and sprawling server farms. WhatsApp pulled it off with a skeleton crew because of an architectural decision made at the runtime level.

Why did WhatsApp need millions of persistent connections open at once?

WhatsApp requires continuous, bidirectional communication between mobile devices and backend servers to deliver messages instantly without battery-draining polling. To achieve this, every active phone maintains an open, long-lived TCP socket directly to WhatsApp's infrastructure. When hundreds of millions of users are online, the system must hold millions of concurrent connections open indefinitely.

In standard request-response web architectures, a client connects, grabs data, and disconnects. Persistent messaging doesn't work that way. If your phone drops its connection, you miss push notifications and messages queue up. Holding that socket open means the server must allocate memory to track the state of that connection for hours, days, or weeks at a time.

How does Erlang handle concurrent connections differently than Java?

Erlang manages concurrency using tiny user-space processes inside the BEAM virtual machine rather than relying on heavy operating system threads. While a traditional thread in a platform like Java typically reserves around 1 megabyte of stack space, an Erlang process starts with an overhead of roughly 2.6 kilobytes.

That difference in footprint changes your hardware requirements entirely. Consider what happens when you need to hold 1,000,000 concurrent socket connections on a single server:

  • Java (Thread-per-connection model): 1,000,000 connections multiplied by 1 MB per thread requires roughly 1 terabyte of memory just to keep the connections idle.
  • Erlang (BEAM process-per-connection model): 1,000,000 connections multiplied by 2.6 KB per process requires approximately 2.6 gigabytes of memory.

Fitting 2.6 GB of idle connection state into a commodity server's RAM is trivial. Fitting 1 TB of memory into a single machine in 2014 was prohibitively expensive, if not physically impossible. Erlang turned a distributed systems hardware bottleneck into a simple in-memory workload.

Concurrency Characteristic Erlang (BEAM Process) Traditional Java (OS Thread)
Allocation Layer User-space virtual machine Operating system kernel
Initial Memory Footprint ~2.6 KB ~1 MB
RAM for 1 Million Sockets ~2.6 GB ~1 TB
Context Switching Overhead Extremely low (cooperative/preemptive in VM) High (requires CPU kernel context switch)

What makes Erlang VM processes so lightweight?

Erlang processes are lightweight because they are isolated software entities managed entirely by the BEAM runtime scheduler, bypassing kernel-level thread management. Each process has its own tiny private heap and stack that grow and shrink dynamically on demand, rather than pre-allocating a large contiguous block of memory up front.

Because there is no shared memory between processes, garbage collection occurs per process rather than across the entire application runtime. If a user connection disconnects, only its tiny 2.6 KB process is reclaimed, eliminating the massive, stop-the-world garbage collection pauses that plague heavy thread-based enterprise runtimes under load. This isolation also means an unhandled error inside one user's connection cannot cascade and crash adjacent connections.

By matching the underlying communication protocol—one socket per user—to an runtime primitive that costs almost nothing to spawn, WhatsApp avoided building layers of defensive infrastructure. A small team could focus entirely on uptime and throughput.

Frequently Asked Questions

What server software did WhatsApp modify to handle these connections?

WhatsApp heavily modified the open-source ejabberd XMPP server, which is written in Erlang. They stripped out unused XMPP features, customized the backend database integration with Mnesia, and tuned the FreeBSD kernel to handle millions of open file descriptors per box.

Why does a standard operating system thread consume so much memory?

Operating system threads reserve a fixed, contiguous stack block (often 512 KB to 1 MB) to prevent stack overflows during deep method calls. Even if an idle socket uses only a fraction of that capacity, the virtual memory overhead remains dedicated to that specific thread.

Can modern runtimes like Go match this connection density?

Yes. Modern runtimes with user-space concurrency primitives, such as Go's goroutines, start with small stacks (around 2 KB to 4 KB) and grow dynamically. This provides a similar density profile to Erlang, allowing single machines to maintain millions of idle connections.

Top comments (0)