Skip to content

Lesson 9 of 9 · 24m

Why Discord Runs Real-Time Infrastructure on the BEAM

Connect Discord's scale requirements to BEAM strengths: millions of connections, fanout, isolation, hot upgrades, pragmatic optimization, and operational control.

Discord is the example people reach for when they need to prove Elixir is not a boutique language. Use it correctly. The lesson is not "Discord uses Elixir, therefore your CRUD app is web scale." The lesson is that BEAM's process model matches real-time messaging infrastructure unusually well.

The workload is hostile

A chat platform has huge numbers of mostly idle connections, sudden bursts, room fanout, presence, reconnect storms, strict latency expectations, and state that is hot but often transient:

millions of websocket connections
small independent connection state
high fanout to rooms or guilds
bursty social behavior

Fanout favors explicit concurrency

When a message enters the system, the core realtime problem is fanout:

incoming event -> routing/ownership -> per-connection messages -> websocket encode and send

A million recipients still means a million deliveries. BEAM does not eliminate cost; it makes concurrency units explicit and isolates failure at the right granularity.

Discord did not use Elixir blindly

Discord's public engineering writing describes Elixir as a major part of real-time messaging infrastructure while also using other languages where appropriate, including Rust for performance-sensitive components. That is mature engineering:

BEAM strengths      coordination, concurrency, isolation, networking
BEAM caution        CPU-bound work, binary copying, hot singleton bottlenecks
Rust/native use     tight performance loops and specialized memory control
external stores     durable truth and cross-system coordination

Use the BEAM as the nervous system, not as a universal replacement for every organ.

Deploys are part of realtime design

BEAM has a long tradition of hot code upgrades, but most Phoenix teams deploy by rolling nodes behind load balancers. At Discord scale, dropping connections creates enormous reconnect storms. At smaller scale the shape is the same: careless deploys can become self-inflicted denial of service.

The real scaling lesson

Discord succeeded because the runtime's concurrency unit matched the product's interaction unit. If your system has many independent, long-lived, event-driven entities — connections, rooms, games, devices, collaborative sessions — the BEAM is compelling. If it is a batch CPU pipeline, the advantage is smaller.

Are there many independent entities?
Do they live longer than one HTTP request?
Is low-latency fanout important?
Does partial failure need isolation?

When most answers are yes, Elixir is not merely productive. It is architecturally honest.

Field notes

  • Discord invested in measurement, customization, and complementary languages; do not cite it as magic.
  • Connection density is constrained by memory, kernel settings, TLS termination, and payload behavior.
  • Fanout tests need realistic payloads and subscriber distribution, not just process counts.
  • Presence and routing state are often ephemeral; entitlements and history are not.
  • The BEAM reward comes with responsibility: understand mailboxes, memory, distribution, and restart behavior.

Was this lesson helpful?

Sign in to rate