Discord's Elixir Scaling: 12 Million Concurrent Users

Discord's Elixir backend, running on the BEAM VM, has handled over 12 million concurrent users and 26 million WebSocket events per second, demonstrating its capacity for massive real-time communication.

The top 3

  1. Elixir's BEAM Processes Outperform Go's Goroutines for Concurrency: Discord's Elixir backend leverages BEAM processes, which are incredibly lightweight (starting around 0.5 KB memory) and isolated, each with its own heap and per-process garbage collection. This contrasts with Go's goroutines (starting around 2 KB) that share a global heap, requiring more complex manual crash recovery and disciplined mutex usage to prevent system-wide failures at scale, enabling Discord to manage millions of concurrent users with a small engineering team.
  2. Discord's Manifold & FastGlobal: Elixir's Fanout Scaling Secret: To handle massive message fanout to millions of users, Discord developed custom solutions like 'Manifold' for hierarchical distribution and 'FastGlobal' for zero-copy data access. These innovations significantly reduced the cost of sending messages from an initial 30-70μs per send to a mere 0.3μs lookup with FastGlobal, preventing performance bottlenecks in large guilds.
  3. Rust's Role: Optimizing Elixir for Discord's Largest Data Structures: While Elixir handles concurrency, Discord faced performance limits with its immutable data structures when managing large, frequently mutating member lists (e.g., 250,000+ items). They integrated Rust via Native Implemented Functions (NIFs) to create a `SortedSet` data structure, achieving significant performance gains (6.5x best-case, 160x worst-case improvement for mutations).

Sources

Open the full topic