A Cassandra table can look excellent when it launches. Writes are fast, median reads are fast, nodes look balanced, CPU is moderate and disk usage is reasonable.
Then months pass. A few partitions become enormous. One customer becomes far more active than everyone else. Deletes and TTL expirations pile up. Compaction starts falling behind. One replica gets noticeably slower than its peers. Average latency still looks fine, but p99 creeps from 40 ms to 150 ms to 800 ms to several seconds. Adding nodes barely helps: the cluster has plenty of CPU, memory and disk overall while a handful of partitions cause most of the pain.
Cassandra didn't suddenly get slower. The workload stopped resembling the distribution the schema was designed for. A data model can be right for today's access pattern and wrong for tomorrow's data distribution.
Cassandra doesn't hide modelling mistakes behind a general-purpose query planner. The partition key, the clustering order and the TTL and deletion behaviour are all architectural decisions. Over time they decide where data piles up, which replicas get the traffic, how many files a read touches, how many deleted rows it has to skip, and how expensive maintenance gets. So beyond "how do I model this table?", it's worth asking what happens to the model after a few years of skew, retention, deletion and growth. Most of the large-scale examples below come from published engineering write-ups by Discord and Uber and from the Apache Cassandra documentation.
How Cassandra stores data
Cassandra's write path is one of its strengths. A write is appended to a commit log and applied to an in-memory table called a memtable. Later, the memtable is flushed to disk as an immutable file called an SSTable (sorted string table). Nothing is rewritten in place.
Reads have a different cost profile. The current value of a row may have to be pieced together from the memtable and several SSTables, each holding a different version. Compaction is the background process that merges SSTables and drops obsolete versions when it's safe, which keeps the number of files a read has to check under control. The compaction overview in the Cassandra docs explains this in detail.
That gives Cassandra an important long-term property: the cost of a read depends partly on the history of writes, updates, deletes, expirations and compactions that produced the current files on disk. A query can be cheap today and expensive later without its CQL changing at all. Modelling in Cassandra is about controlling the physical shape a query will run into once the data has aged.
Even tokens, uneven work
Here's a reasonable message table:
CREATE TABLE messages_by_channel (
channel_id UUID,
bucket_date DATE,
message_id TIMEUUID,
author_id UUID,
content TEXT,
PRIMARY KEY (
(channel_id, bucket_date),
message_id
)
);
The partition key is (channel_id, bucket_date): Cassandra hashes it to decide which nodes store the partition. Messages for one channel and one day stay together, and the main query fits directly:
SELECT *
FROM messages_by_channel
WHERE channel_id = ?
AND bucket_date = ?
ORDER BY message_id DESC
LIMIT 50;
Now compare two channels:
| Channel | Members | Messages per day |
|---|---|---|
| A | 12 | 100 |
| B | 500,000 | millions |
Hashing spreads partition keys evenly around the cluster. It can't make the work behind each key equal. Consistent hashing distributes many partitions across many nodes, but it doesn't split one unusually busy partition into smaller pieces. A cluster can look perfectly balanced in aggregate while one set of replicas does far more work than the rest.
Hot partitions and their neighbours
Imagine four nodes, each holding one channel's partition:
Storage might be balanced while reads look like 10k/s on node 1, 190k/s on node 2, 12k/s on node 3 and 11k/s on node 4. The cluster has spare capacity; node 2 doesn't.
Discord hit exactly this in How Discord Stores Trillions of Messages. Messages were partitioned by channel plus a time bucket, and a burst of activity in a big server's channel created a hot partition. Because Discord read and wrote at QUORUM (a majority of replicas must respond), every query hitting the nodes that held that partition slowed down, not just queries for the busy channel.
That's the part that's easy to underestimate. A node serves many partitions, so when one hot partition eats CPU, disk I/O, request slots and heap, unrelated cold partitions on the same node wait behind it. Logical skew becomes a noisy-neighbour problem.
The consistency level also shapes latency. With a replication factor of 3 and quorum reads, a request involves several replicas, so one slow replica can show up in user-facing latency depending on which replicas answer and whether speculative retries are on. Consistency level is about correctness, but it also affects the shape of your latency.
And this is why adding nodes doesn't automatically fix a hot partition. The cluster gains capacity, but the hot key still maps to one set of replicas.
Partitions that keep growing
Uneven traffic is one problem. Uneven size is another. A partition that starts at 10 MB might eventually reach 500 MB, or several gigabytes, depending on the schema and workload. Large partitions make reads, compaction, repair, streaming between nodes, backups and migrations all more expensive, and they increase memory pressure.
The Leveled Compaction Strategy docs show how fundamental the partition boundary is: when one partition is exceptionally large, compaction produces an SSTable bigger than the target size, because Cassandra won't split a partition across two SSTables. Once you've picked the partition key, most later storage operations inherit that decision.
This matters even when normal reads still look fine. A partition that barely affects one paginated application query can be painful for repair, streaming, backups or a migration job that has to read all of it. The partition isn't only a serving concern; it shows up in every operational tool that touches the data later.
Bucketing is a prediction
The usual fix for partitions that grow without limit is time bucketing: instead of partitioning by device_id, partition by device_id plus day (or hour). That caps how much data lands in one partition.
It also quietly predicts that one day is the right bucket size for every device. If device A sends 20 measurements a day and device B sends 50 million, the same bucket gives wildly different partitions. Larger buckets risk wide partitions; smaller buckets keep partitions small but mean more partitions and more fan-out for longer queries. The question usually isn't "partition or not?" but where the useful middle sits between partitions that are too wide and queries that are too fragmented. Static buckets work while the workload stays close to the assumptions they were chosen for. Growth can break those assumptions.
Every bucketing scheme moves cost somewhere:
| Scheme | Example key | What it fixes | What it costs |
|---|---|---|---|
| Time bucket | customer_id + day | Unbounded partition growth | A 30-day query reads 30 partitions; a year reads 365 |
| Hash bucket | customer_id + hash(event_id) % 16 | One hot write partition | Reading a customer's events means 16 reads plus a merge |
Those can be excellent trades. They're still trades. The familiar Cassandra advice is "model around your queries". I'd add: model around your queries and the future distribution of the data those queries will touch.
Deletes become tombstones
You might expect DELETE FROM messages WHERE ... to make the data disappear. A replicated database can't do that safely. Instead, Cassandra writes a tombstone: a timestamped marker that says "this value was deleted".
The reason is that one replica might have been offline during the delete. If the healthy replicas simply forgot the value while the offline one still had it, the old copy could come back later. A tombstone isn't garbage; it's the evidence that keeps deleted data deleted.
That makes deletion part of the read path. Suppose a partition once held 1,000,000 rows and most have since been deleted or expired. A query for the newest 50 live rows may have to step over far more dead entries to find them. The table can hold very little live data and still be expensive to read, because its deletion history is still on disk. Tombstones stay until compaction can safely remove them, and TTL expiry creates tombstones too, so a TTL isn't free cleanup. It schedules future deletion and compaction work.
Discord's migration story has a memorable example. Moving trillions of messages to a new database, their migrator got to 99.9999% and stopped. The last few token ranges contained huge runs of tombstones that had never been compacted away, and reads of those ranges kept timing out. They had to compact those ranges before the migration could finish. The tombstones hadn't broken normal requests, but the storage debt was waiting for the first job that had to read everything.
Compaction pays the bill later
Because SSTables never change, updates and deletes add new information rather than rewriting old files. Over time a single logical read may need pieces from several SSTables. Compaction merges them into one, which means fewer files to check per read and space reclaimed from obsolete versions and expired tombstones.
Compaction itself uses CPU, disk I/O and temporary disk space, so Cassandra is always doing background work just to keep foreground reads healthy. When writes arrive faster than compaction can keep up, pending compactions grow, each read touches more SSTables, disk I/O rises and latency follows. At the same time, compaction tries to catch up and adds even more I/O. The node is doing more maintenance exactly when foreground work is getting more expensive.
Discord describes this directly. When compaction fell behind, reads got more expensive and the node's attempts to catch up caused cascading latency. They regularly took a node out of rotation so it could compact without serving traffic, then brought it back to receive missed writes through hinted handoff. They called this the "gossip dance". It's a clear case of maintenance debt turning into request latency.
There's no single best compaction strategy. Each one trades between read amplification (how many SSTables a read checks), write amplification (how many times data is rewritten) and space amplification (how much extra disk is used). The Unified Compaction Strategy docs describe this as a single dial: more leveled behaviour lowers read cost and latency at the price of more rewriting; more tiered behaviour favours writes and makes reads more expensive. A read-heavy serving table and a TTL-heavy time series probably shouldn't use the same settings. Compaction strategy is part of the data model, not housekeeping chosen separately.
Repair and deleted data coming back
Replication gives fault tolerance, and it also means replicas can drift apart. Nodes are down during writes, networks partition, disks fail, machines get replaced. Repair (anti-entropy) compares replicas and reconciles them. It costs network, disk, CPU and operator attention, and at large scale keeping it healthy is real work. Uber's article on optimising Cassandra operations at scale mentions that stakeholders complained about data inconsistency from data resurrection, and that the cause was repair running too slowly.
Here's how deleted data can come back. With three replicas holding value X, replica C goes offline and X is deleted. A and B now hold a tombstone; C still holds X. Tombstones are kept for a grace period (gc_grace_seconds) so that offline replicas have time to come back and learn about deletes, and after that compaction can purge them. If repair hasn't brought C up to date before the tombstones on A and B are purged, nothing remains to prove X was deleted, and C's stale copy can reappear.
So a setting that sounds like cleanup is part of the correctness model. Shortening tombstone retention because tombstones are slowing reads, without making sure repair completes within that window, trades a performance problem for a data correctness problem. That's rarely a good trade.
Hinted handoff sometimes gets confused with repair. When a replica is briefly down, other nodes keep "hints" of the writes it missed and replay them when it returns. That's useful for short outages, but it doesn't replace repair: hints cover recent missed writes, while repair reconciles replicas over the long term.
Watching the tail
If 99% of partitions answer in 15 ms and 1% take 800 ms, the average is about 23 ms and the dashboard looks fine. A user whose data lives in a slow partition experiences a completely different database. So I want p50, p95, p99 and p99.9, and I want them broken down by the things that cause them: latency by partition, by coordinator and by replica, plus lists of the largest and hottest partitions. A global percentile tells you a tail exists; it doesn't tell you which data shape is causing it.
The JVM adds to the tail too. Classic Cassandra runs on the JVM, so garbage collection pauses enter the latency picture. Discord reported spending a lot of effort on GC and heap tuning, with pauses causing significant latency spikes. Average CPU can look normal while a pause on one important replica shows up only in p99 and p99.9.
That's why I think of Cassandra's p99 as partly a data-model metric. A stable median with a worsening tail can point to hot partitions, wide partitions, tombstone-heavy reads, a slow replica, compaction interference, GC pauses or repair activity. The problem shows up in the tail long before the median admits anything is wrong.
Fixing it above the database
Discord eventually moved its messages from Cassandra to ScyllaDB, but they were explicit that changing the database alone wouldn't fix hot partitions. A hot key stays hot. So they added a data-service layer in front of storage, and its main feature was request coalescing: if many users request the same row at the same time, the database is queried once and the result is shared. They also routed requests for the same channel to the same data-service instance using consistent hashing, which made it more likely that duplicate concurrent reads could be merged.
The broader point is that not every database bottleneck has to be fixed inside the database. A hot read can often be handled with coalescing, a cache, batching upstream, rate limiting or smarter routing, instead of asking the database to run the same expensive query thousands of times.
When a key outgrows its partition
Suppose the original model is PRIMARY KEY ((customer_id), timestamp) and it works well, until one enterprise customer becomes 1,000 times larger than the median. There are several ways forward:
- Time buckets (
customer_id + monthor+ day) cap partition size but make long time-range queries fan out. - Hash buckets (
customer_id + shard_number) spread writes but make reads query and merge several partitions. - Adaptive partitioning treats unusually large identities differently. It fits real skew better but adds routing and metadata.
- Request coalescing or caching leaves the storage model alone and reduces duplicate reads.
- Migrating to a new model accepts that the original partitioning has reached the end of its useful life.
None of these is free. They move complexity between write distribution, read fan-out, routing, metadata, cache consistency and migration cost.
Adding nodes deserves a mention here because it's often the first thing tried. Going from 20 to 40 nodes helps when the bottleneck is total storage or throughput for well-spread traffic. It does much less for one huge partition, one hot key, one pathological query, one tombstone-heavy read or one overloaded replica set. Nodes add capacity; they don't reshape the partitioning.
If the partition key no longer fits the workload, configuration probably can't fix it, and changing a PRIMARY KEY usually means a new table. That's a staged migration: create the new schema, dual-write, backfill history, validate, switch reads, then retire the old table. Discord did this at enormous scale: dual writes, custom migration tooling, comparing reads between old and new stores before moving production traffic. Importantly, the architecture around the database changed too.
None of this means Cassandra failed. Discord chose it for scalability and fault tolerance, and grew from billions to trillions of messages on it. The hard behaviour came from the combination of huge growth, skew, hot and wide partitions, compaction, JVM behaviour and maintenance, not one simple flaw. Uber continues to run Cassandra for critical workloads at large scale. Distributed databases don't remove data-model constraints; they make different constraints important.
Reviewing and testing a model
The partition that hurts you is rarely the median one. A median partition size of 5 MB sounds great; a p99 of 800 MB and a maximum of 19 GB describe a very different system. So I watch distributions, not cluster averages: bytes and rows per partition, reads and writes per partition, tombstones scanned per read and SSTables touched per read.
Before approving a new Cassandra model, I'd want answers to these:
| Area | Question |
|---|---|
| Partition growth | How large can the biggest partition get in a year? |
| Workload skew | What happens if one customer becomes 1,000× more active than the median? |
| Deletion | Will TTLs or deletes cause heavy tombstone scans? |
| Read path | How many partitions does a real query touch? |
| Compaction | Does the strategy match how the data is written, read and expired? |
| Repair | Can repair finish within gc_grace_seconds? |
| Hot reads | Should repeated access be coalesced or cached upstream? |
| Observability | Can we find the largest and hottest partitions before users complain? |
| Operations | Can backup, migration, repair and streaming handle the largest partition? |
For a table that keeps 30 days of data with a TTL, the review shouldn't stop at writes per second. It should also ask how many rows expire per second, how many tombstones will build up, how often queries scan expired ranges, and how often repair can complete. TTL changes the storage workload, so retention design is data-model design.
Load tests need the right shape, not just the right volume. A million evenly spread requests isn't the same workload as production, where half the requests might hit 0.1% of the keys. A realistic test varies the key distribution (uniform and heavily skewed, which is often modelled as a Zipf distribution), includes hot-key bursts, large partitions, TTL-heavy and delete-heavy data, and runs compaction and repair while foreground traffic is flowing. Then it watches p50 through p99.9, SSTables per read, tombstones scanned, pending compactions, disk usage, GC pauses and per-replica latency. Many of Cassandra's worst cases are local rather than cluster-wide, and a perfectly even benchmark is almost designed to hide them.
Finally, when latency rises, diagnose the data shape before turning knobs. It's easy to change heap size, compaction throughput, concurrent reads, cache settings, consistency level or gc_grace_seconds and temporarily move the symptom. I'd rather first establish which queries are slow, which partitions they touch and how big those are, how many SSTables and tombstones each read hits, which replicas are slow, whether compaction is behind or repair is running, and whether the problem tracks particular keys. Then tune or remodel. Otherwise configuration turns into archaeology.
The question I keep coming back to with Cassandra isn't "will this query be fast?" but "what will the worst version of this partition look like after a few years of growth?" If the design still holds up in that scenario, it's probably durable. If it doesn't, the problem may already exist, just not visible in the tail yet.
Key takeaways
- Even token distribution doesn't mean even work. Plan for the hottest and largest partitions, not the median.
- Choose partition keys and bucket sizes with future growth and skew in mind, and know what fan-out each choice adds to reads.
- Deletes and TTLs create tombstones that stay until compaction can safely purge them. Retention design is data-model design.
- Make sure compaction can keep up with steady-state writes, and pick a strategy that matches how the table is read and expired.
- Repair must finish within
gc_grace_seconds, or deleted data can come back. - Watch per-partition and per-replica tail latency, and test with realistic skew, not evenly spread load.
- When a key outgrows its partition, more nodes won't fix it. Reshape traffic upstream or migrate to a new model.
References
- Discord — How Discord Stores Trillions of Messages — hot partitions under quorum reads, compaction backlog and the "gossip dance", GC pauses, the tombstone-blocked migration, and request coalescing.
- Apache Cassandra — Compaction overview — SSTables, tombstones, TTL expiry, the grace period and what compaction does.
- Apache Cassandra — Leveled Compaction Strategy — how LCS sizes SSTables, and why an oversized partition produces an oversized SSTable.
- Apache Cassandra — Unified Compaction Strategy — the trade-off between read amplification and write amplification, tuned with one parameter.
- Uber — How Uber Optimized Cassandra Operations At Scale — running Cassandra for critical workloads, including repair, node replacement and data resurrection caused by slow repair.
