Discord
Realtime chat with Elixir and a hybrid DB/NoSQL backend
Discord serves real-time guild chat with Elixir/OTP (millions of concurrent connections), ScyllaDB for message history, and Redis for presence/sessions. Messages fan out to online members via persistent connections; history is queried from ScyllaDB.
Product constraints
- Millions of concurrent connections; low-latency message delivery.
- Message history must be queryable and durable at huge scale.
- Presence and typing indicators are high-frequency, ephemeral.
- Guilds (servers) can have huge member counts; fan-out is large.
High-level diagram
Request path
- Send message. Client sends over a persistent connection (Elixir/OTP gateway); the message is persisted to ScyllaDB.
- Fan-out. The gateway fans the message to all online members' connections across nodes (inter-node via Redis/pub-sub).
- Presence. Presence and typing state kept in Redis, ephemeral and high-frequency.
- History. Offline/later reads query ScyllaDB by channel id, ordered by message id (time-based).
Data model
Messages in ScyllaDB partitioned by channel id, clustered by message id (time-ordered). Guilds/channels/members in a mix of DBs. Presence, sessions, and ephemeral state in Redis.
Storage / cache / queue choices
Storage
ScyllaDB (Cassandra-compatible) for message history, partitioned by channel.
Scaling levers
- Elixir/OTP lightweight processes handle millions of connections per node.
- ScyllaDB partitions by channel for write throughput and channel-scoped reads.
- Redis pub/sub for cross-node fan-out to online members.
- Separate ephemeral (presence, Redis) from durable (messages, ScyllaDB) state.
Copy vs skip (for a smaller team)
Copy
- Partition message history by channel (chat id) for write scale.
- Use a connection-optimized runtime (Elixir/OTP or similar) for fan-out.
- Keep ephemeral state (presence) in a cache, not the DB.
- Pub/sub for cross-node fan-out to online members.
Skip
- Storing presence/typing in the DB (ephemeral — use a cache).
- Elixir specifically without expertise (use any actor/connection model).
- Single-node fan-out (shard by guild).
Related terms
WebSockets, Cassandra, Redis, Pub/Sub, Partition