Discord keeps every chat message forever, and by the start of 2022 that meant trillions of messages in one database table. The table has lived in three databases: MongoDB, then Cassandra, then ScyllaDB. Discord's engineers wrote up each move in detail, and together the two posts are one of the clearest public lessons in how a partition key, deletes and a garbage collector decide whether a database stays healthy.
Everything below comes from those two posts, published in January 2017 and March 2023. Figures carry the year they were reported.
From one MongoDB replica set to Cassandra
Discord was built quickly in early 2015, and all of its data went into a single MongoDB replica set. Messages sat in one collection with a compound index on channel_id and created_at. Sharding was deliberately not used.
That worked until around November 2015, when the collection reached 100 million messages. At that point the data and its index no longer fitted in RAM. Once an index does not fit in memory, lookups turn into disk reads at unpredictable moments, and Discord saw exactly that: latency became erratic.
Before choosing a replacement the team studied how messages were actually read. Reads were very random, and the read to write ratio was about 50/50. Servers also differed enormously. A voice-focused server might send under a thousand messages a year, which meant fetching 50 of them could touch many scattered places on disk. A large public server sent millions a year, nearly all read within the hour.

The 2017 post lists what the team wanted from a replacement: capacity that grows by adding nodes without manual resharding, automatic failover, low maintenance, a proven track record, predictable performance, and open source. They did not want to bolt a cache in front of the database to hide slow queries. Cassandra was the one system they found that satisfied the whole list.
Cassandra is a wide-column store in the Dynamo tradition. Nodes form a ring, each row is hashed to a position on the ring, and several nodes hold a copy. There is no primary node to fail over. Discord used a replication factor of three. In 2017 the messages cluster was 12 nodes holding roughly 1 TB each, and the post reports writes under a millisecond and reads under five.

The partition key: channel plus time bucket
In Cassandra the primary key has two parts. The partition key decides which nodes hold a row, and all rows sharing a partition key are stored together. The clustering key sorts rows inside that partition. A query that names one partition is cheap. A query that has to visit many is not.
The obvious first design was a partition per channel, sorted by time. Discord replaced created_at with message_id, because two messages can share a timestamp, while Discord's IDs are Snowflakes: unique numbers that begin with a timestamp and so sort chronologically.
A partition per channel has a flaw. A busy channel never stops growing, so its partition never stops growing. During the import Discord saw partitions above 100 MB, and large partitions put heavy pressure on Cassandra's memory during compaction. A partition also cannot be split across nodes.
The fix was to add a time bucket to the partition key. Each bucket covers about ten days, a size chosen so that even the largest channels stayed under 100 MB per partition. A simplified form of the table Discord published looks like this:
CREATE TABLE messages (
channel_id bigint,
bucket int,
message_id bigint,
author_id bigint,
content text,
PRIMARY KEY ((channel_id, bucket), message_id)
) WITH CLUSTERING ORDER BY (message_id DESC);
Loading recent messages means computing the current bucket from the clock, reading that one partition, and stepping back to older buckets only if more messages are needed. The bucket is derived from the timestamp inside the message ID, so no lookup table is required.
The first surprise: tombstones
Cassandra never modifies data files in place. A write appends to a log and an in-memory table, which is later flushed to an immutable file on disk. A delete therefore cannot remove anything. It writes a marker called a tombstone, which says that the row is gone as of a certain time. Reads must collect tombstones along with live rows and discard what they cover. The tombstones themselves are only dropped by compaction after a grace period, ten days by default at the time.
About six months after launch, Discord found one channel that took 20 seconds to load and was driving a node into repeated ten-second garbage collection pauses. The channel belonged to a public server and contained a single message. Its owners had deleted millions of others through the API. Every attempt to load the channel made Cassandra walk across millions of tombstones to find one live row, creating garbage in the Java heap faster than it could be collected.
Discord made two changes. Since repairs ran nightly on this cluster, the tombstone grace period could safely drop from ten days to two. And the application began remembering which buckets of a channel were empty, so that it would not scan them again.
A related lesson came from writes. In Cassandra, writing a null into a column also creates a tombstone. Discord's full table had 16 columns and the average message set only four of them, so writing whole rows produced twelve pointless tombstones per message. The fix was to write only the columns that have values.
Eventual consistency caused its own bug. Every Cassandra write is an upsert. If one user edited a message while another deleted it, the edit could recreate a row containing only the key and the new text. Discord chose to treat any message with a missing author as corrupt and delete it on read.
Why Cassandra stopped working at 177 nodes
By the start of 2022, per the 2023 post, the messages cluster had grown from 12 nodes to 177 and held trillions of messages. It had also become a constant source of on-call pages. The post names three causes.
Hot partitions. Bucketing bounds the size of a partition, not the traffic to it. When a server with hundreds of thousands of members gets busy, everyone reads the same channel and bucket. Those reads land on the same three replicas. Because Discord read and wrote at quorum consistency, a slow node delayed every query that needed it, including queries for unrelated channels.
Compaction debt. In an LSM-tree database, a read may have to check the in-memory table and several files on disk, and compaction is the background job that merges those files to keep reads cheap. Discord's cluster regularly fell behind on compaction, which made reads slower, which made the hot partition problem worse. Operators developed a manual routine, which the team called the "gossip dance", of taking a node out of rotation so it could compact without serving traffic and then bringing it back.
Garbage collection. Cassandra runs on the JVM. Long collector pauses showed up directly as latency spikes, and the worst cases needed an operator to restart the node by hand.
The move to ScyllaDB
ScyllaDB speaks the same query language and uses the same data model as Cassandra, but is written in C++. It has no garbage collector, and it assigns each CPU core its own slice of the data, which isolates workloads from one another. By 2020 Discord had moved every database except messages to it. Messages waited until ScyllaDB improved the performance of reverse queries, meaning scans in the opposite order to the table's sort, which Discord needs for some message fetches.
Before migrating, the team put a new layer between the API and the database: data services written in Rust. Each service exposes roughly one gRPC endpoint per database query and holds no business logic. Its main trick is request coalescing. If many users ask for the same row at the same moment, the first request starts a database query and the rest simply wait for that result. The services are reached through consistent hash routing on the channel ID, so all requests for one channel arrive at the same instance, which is what makes coalescing effective. This reduced the damage from hot partitions but did not remove them.
The migration itself used a standard pattern. New messages were written to both databases from a cutover time, and history was copied in the background. ScyllaDB's Spark-based migrator was estimated to take three months. The team instead reused their Rust data service code to write a migrator that read token ranges, recorded its progress in a local SQLite file, and wrote to ScyllaDB. The estimate became nine days, at up to 3.2 million messages per second.
It stalled at 99.9999% complete. The last token ranges contained huge runs of tombstones that Cassandra had never compacted away, and reads over them timed out. Compacting those ranges let it finish. The team then verified the copy by sending a small share of live reads to both databases and comparing answers, and switched over in May 2022.
What changed, and what it cost
| Measure (2023 post) | Cassandra | ScyllaDB |
|---|---|---|
| Nodes | 177 | 72 |
| Disk per node | about 4 TB average | 9 TB |
| p99 fetch of historical messages | 40 to 125 ms | 15 ms |
| p99 message insert | 5 to 70 ms | 5 ms |
The trade-offs are worth stating. Discord kept an eventually consistent data model, with all the application-level care that requires. It accepted a rewrite of its data access layer and a period of running two systems side by side. And the new database did not make hot partitions impossible. What changed is that the tail latency and the manual operations went away. The post notes that the 2022 World Cup final was visible in the message graphs, goal by goal, without the database struggling.
The computer science underneath
Wide-column stores and choosing a key. Cassandra and ScyllaDB belong to the wide-column family described in NoSQL: the four families. You design the table around the query, and the partition key is the most important decision. A good key spreads data evenly and lets common queries hit one partition. Discord's (channel_id, bucket) is a textbook compound key, and its hot partition trouble is the textbook limit: you can bound size with a time bucket, but not popularity. See shard keys, resharding and cross-shard queries.
LSM trees. Appending to a log, flushing sorted files and merging them later makes writes very fast and pushes cost onto reads and background compaction. Tombstones follow directly from immutable files. All of it is covered in LSM trees and SSTables.
Dynamo-style replication. A ring of equal nodes, a replication factor and tunable quorums give high availability without a primary, at the price of eventual consistency and upsert semantics. Key-value stores and Dynamo-style design explains why a read at quorum must wait for a majority of replicas, which is how one slow node hurt Discord's latency.
Consistent hashing. The same idea places partitions on database nodes and routes a channel's requests to one data service instance. Consistent hashing in depth covers the mechanics.
What an interviewer could ask from this
Why not partition messages by channel alone? The partition grows without limit. Large partitions slow compaction and repair and cannot be split across nodes. Adding a time bucket caps partition size.
Why can deleting data make reads slower in Cassandra? Deletes write tombstones. Until compaction removes them after the grace period, every read over that range must scan and discard them.
Why not remove tombstones immediately? A replica that was down during the delete still holds the old row. If the tombstone vanished before repair reached that replica, the deleted data would be copied back. The grace period must exceed the repair interval.
What is a hot partition, and how can you soften it? One partition key receiving a disproportionate share of traffic, overloading its replicas. Options include finer keys, caching, and coalescing identical requests so that concurrent readers share one query.
How do you migrate a live database without downtime? Dual-write new data, backfill history in resumable chunks, compare reads from both systems on a sample of traffic, then switch reads and retire the old store.
Why did a database with the same data model perform better? No garbage collector pauses and a per-core architecture that isolates work. The data model was not the problem. The runtime and the operational cost were.
Takeaways
- Choose a partition key from your read pattern, and check that it bounds partition size. Time bucketing is the standard tool for append-heavy data.
- In log-structured stores, deletes and nulls are writes. Heavy deletion needs a plan.
- Tail latency in a quorum system is set by the slowest replica you must wait for, so pauses on one node spread.
- A thin data service layer gives you one place to add coalescing and routing, and makes it far easier to swap the database underneath.
- Migrations finish at 100%, not 99.9999%. Budget for the awkward last ranges and verify with real traffic.












