BEAM's Lightweight Processes: WhatsApp's Billion-User Concurrency
Erlang's BEAM Virtual Machine enables WhatsApp to manage millions of concurrent user connections by assigning each to an extremely lightweight process, consuming only hundreds of bytes of memory, far less than traditional threads.
The top 3
- BEAM Processes: Orders of Magnitude Lighter than OS Threads: Erlang processes are exceptionally lightweight, typically requiring only 2-3 KB of memory, which allows for millions to run concurrently on a single machine. In contrast, traditional OS threads often demand 1-2 MB of stack space, severely limiting the number of threads a system can support.
- BEAM's Scheduler: Fair Execution for Millions of Processes: The BEAM virtual machine employs a preemptive scheduler that allocates CPU time in small 'reductions,' ensuring fair execution and preventing any single process from monopolizing resources. This, combined with complete process isolation and message passing, eliminates the need for locks and complex synchronization.
- WhatsApp's Secret: One Erlang Process Per User Connection: WhatsApp scaled to billions of users by leveraging BEAM's lightweight processes, dedicating a separate Erlang process for each user connection. This 'process-per-connection' model enables a single WhatsApp server to efficiently manage over 2 million concurrent connections.
Sources
Open the full topic