Blog 5 — Discord: How We Store Billions of Messages
C
Qubits of DPK
March 21, 2026
Core Case Studies
Core Concept: MongoDB → Cassandra → ScyllaDB migration, Time-series data storage
Why SDE-2 Critical: Storage decisions at scale — why you pick which DB for which workload
Status: Draft notes ready
Quick Revision
- Problem: Store massive chat history with fast append and recent-message reads.
- Core pattern: Time-bucketed wide-column storage with Cassandra/ScyllaDB.
- Interview one-liner: Pick a database around the access pattern, not the brand name.
️ The Journey: 3 Database Migrations
javascript
QUBITS OF DPK
Core Concepts
Why MongoDB Failed
javascript
QUBITS OF DPK
Why Cassandra Was Chosen
- Designed for time-series data (perfect for chat messages)
- Wide column model: partition = channel, rows = messages ordered by time
- Linear horizontal scaling — add nodes, capacity grows linearly
- Tunable consistency — Discord chose eventual consistency (fine for chat)
Cassandra Data Model for Messages
javascript
QUBITS OF DPK
The Bucket Problem
- A channel with 10 years of messages in one partition = too large
- Discord splits by time bucket (e.g., monthly)
- Old bucket = cold storage, recent bucket = hot
Why ScyllaDB Over Cassandra
javascript
QUBITS OF DPK
Scale Achieved
5 Interview Questions This Blog Unlocks
Q1. Design a chat system like WhatsApp / Slack
Answer: Use Cassandra/ScyllaDB with partition key = (channel_id, time_bucket), clustering key = message_id. Recent messages read from hot partition. Historical messages from cold buckets. WebSockets for real-time delivery. Kafka for fan-out to group members.
Q2. Why is Cassandra good for time-series data?
Answer: Cassandra's wide column model naturally maps to time-series. Partition = entity (channel/user/device), rows = time-ordered events. Append-only writes are extremely fast. Range queries by time are efficient. No JOINs needed.
Q3. What is the difference between relational and wide-column databases?
Answer: Relational: fixed schema, rows have same columns, optimized for JOINs and transactions. Wide-column: flexible schema, rows in same partition can have different columns, optimized for massive write throughput and range queries by partition + clustering key.
Q4. How would you handle message deletion in a Cassandra-based chat system?
Answer: Cassandra uses tombstones for deletion (soft delete marker). Hard deletes are expensive. Better approach: mark message as deleted in application layer, filter on read. Compact tombstones periodically. Never rely on frequent hard deletes in Cassandra.
Q5. Why did Discord migrate from Cassandra to ScyllaDB with zero downtime?
Answer: ScyllaDB is wire-compatible with Cassandra (same CQL protocol). Migration strategy: run both in parallel → double-write to both → gradually shift reads to ScyllaDB → verify data consistency → decommission Cassandra. Application code unchanged.