1. Scale & Real-Time Challenges
Discord connects hundreds of millions of users across persistent community servers called 'guilds'. Some mega-guilds contain over 1 million members. When a user changes their status from 'Offline' to 'Online', naively broadcasting that presence update to all 1 million guild members requires 1,000,000 WebSocket messages.
If 100 users toggle status simultaneously, that produces 100 million messages, overwhelming the network. Discord solved this with intelligent presence subscription.
2. Gateway Tier: Erlang & Elixir on BEAM
Discord's real-time gateway is powered by Elixir on the Erlang VM (BEAM). The BEAM process model allows millions of lightweight concurrent actor processes on a single physical machine with microsecond scheduling.
Each client maintains a persistent WebSocket connection to a gateway process that handles heartbeats, sequence numbering, and session resumption.
3. Presence Optimization: Viewport-Based Subscriptions
For large guilds, Discord does not broadcast presence updates to everyone. Instead, clients only subscribe to members currently visible in their sidebar viewport (typically ~30 to 50 members). As the user scrolls, new subscription windows are requested lazily.
4. Trillion-Message Storage with ScyllaDB & WebRTC Voice
Discord migrated from MongoDB to Cassandra and ultimately to ScyllaDB (C++ rewrite of Cassandra) to store trillions of messages with low p99 latency without JVM garbage collection pauses.
Voice channels use WebRTC with custom Selective Forwarding Units (SFUs) written in Rust/Go, routing UDP audio packets between participants without transcode overhead.
Model this architecture on the HLDForge Canvas
Turn static box diagrams into living, collaborative systems. Drag and drop microservices, Kafka clusters, and cache tiers. Run automated SPOF detection and STRIDE threat modeling in real time.
Written by HLDForge Architecture Team
Principal Real-Time Systems Architect
The HLDForge Architecture Team publishes practical engineering guides, real-world case studies, and high-concurrency blueprints to help engineers build scalable and fault-tolerant software.