How does Cassandra take so many writes, and why is it so picky about queries?
This page is about a database built for writes spread across many machines, with no primary. I show you where a write goes (commit log, memtable, SSTable), how the partition key decides which machines hold your data, and why deletes and queries the key cannot answer cause most of the trouble. After it you will be able to design a table from its queries, pick a consistency level, and read nodetool's view of the cluster.
A wide-column database: rows grouped into partitions by a key, partitions spread across a ring of equal nodes, every write appended and never updated in place.
Good at: Huge write rates, data that grows forever, several data centres, no single node that must stay up. Time series, messages, event history.
Runs as: one Java process per node; every node is equal; replication per keyspace, consistency per queryThere is no primary and no failover. Any node can take a request and pass it to the nodes that own the data.
The same layers as a still diagram, with every part named:
Write path on each replica
| Place | What it holds | What to watch |
|---|---|---|
| commitlog/ | every write, appended before it is acknowledged | commitlog_sync is periodic by default, flushing every 10 seconds, so a power cut on every replica at once could lose the last seconds. The batch and group modes wait for the disk. |
| Memtable | recent writes, sorted, in memory | Flushed to an SSTable when full. Big memtables mean more commit log to replay after a crash. |
| SSTables | immutable sorted files; a read may have to look in several | SSTables per read in nodetool tablehistograms. Compaction keeps the count down. |
| Tombstones | markers for deleted data, kept until compaction after gc_grace_seconds (10 days by default) | Reads that scan many tombstones get slow, and fail at tombstone_failure_threshold (100,000). |
| hints/ | writes for a replica that was down, kept up to max_hint_window (3 hours) | Longer outages need nodetool repair to catch up. |
Replication factor 3, one chat message, written at QUORUM. Step through it, then tick the box.
Yes. Two of three is a quorum. The coordinator keeps a hint for the missing replica. At consistency ALL the same write would fail. Tick the box in the widget to step through it.
| Setting | Default | What it trades |
|---|---|---|
| Replication factor | set per keyspace | How many copies. Three per data centre, with NetworkTopologyStrategy, is the usual choice. |
| Consistency level | per query; often LOCAL_ONE in the drivers | ONE: fastest, can read stale data. QUORUM or LOCAL_QUORUM: reads see acknowledged writes. ALL: fails if any replica is down. |
| commitlog_sync | periodic, every 10 s | batch or group waits for the disk before acknowledging. Periodic relies on other replicas for safety. |
| Compaction strategy | SizeTiered is the long-standing default | Leveled for read-heavy tables, TimeWindow for time series with TTLs. The Unified strategy in 5.0 can behave like either. |
| gc_grace_seconds | 864000, 10 days | How long deletes are remembered. Run a full repair more often than this. |
| Partition key | your choice, per table | Decides which nodes hold a row and how big a partition gets. The most important decision in a Cassandra design. |
| What happens | What you see | What I do |
|---|---|---|
| A partition that grows forever | One node hot, slow reads, compaction struggling | Add a time bucket to the partition key, such as (conversation_id, month). Keep partitions well under 100 MB. |
| Tombstones read in a range | Slow reads, then TombstoneOverwhelmingException | Model reads so they do not scan deleted rows. TimeWindow compaction for data that expires with a TTL. |
| Repair not run within gc_grace_seconds | Deleted data comes back | Schedule repair. Cassandra 6.0 builds repair in. |
| A query the key cannot answer | Rejected unless you add ALLOW FILTERING, then a scan of every node | A second table keyed for that query, or a storage-attached index (5.0) for selective filters. |
| Read, change, write | Lost updates: writes are last-write-wins by timestamp | Write without reading first. Use counters, or lightweight transactions (IF ...) where you truly need compare-and-set. |
| Lightweight transactions everywhere | Writes several times slower | Use them only for the few rows that need them. |
| Clocks out of step | An older write wins over a newer one | NTP everywhere, and let the server assign timestamps. |
nodetool status # every node: up or down, load, ownership nodetool tablestats chat.messages # SSTables, partition sizes, tombstones per read nodetool tablehistograms chat messages # SSTables per read, partition size percentiles nodetool compactionstats # compactions running and pending nodetool tpstats # thread pools, dropped messages, hints nodetool repair -pr chat # repair this node's primary ranges cqlsh> CONSISTENCY QUORUM; cqlsh> TRACING ON; # then run a query: where it spent its time, replica by replica
Versions and licences. Cassandra 5.0 (September 2024; 5.0.9 in August 2026) added storage-attached indexes, vector search, the Unified Compaction Strategy, and trie-based memtables and SSTables. Cassandra 6.0 is in alpha in 2026 with Accord, ACID transactions across partitions, and transactional cluster metadata; check its status before you plan on it.
A chat app stores messages with PRIMARY KEY (channel_id, sent_at). One channel has 50 million messages, and reads for it are slow on the same few nodes. What is wrong, and what would you change?
Write your answer down first. Then open mine.
What is wrong: the partition key is channel_id alone, so the whole channel is one partition on the same three replicas. At about 300 bytes a message that is roughly 15 GB in one partition: one hot set of nodes, long compactions, and reads that walk a huge partition.
What I would change: add a time bucket, PRIMARY KEY ((channel_id, day), sent_at), or month for quieter channels, so each partition stays well under 100 MB. The app reads the latest bucket first and walks back.
And: old buckets can expire with a TTL and TimeWindow compaction, so retention is files being dropped, not millions of tombstones.
The same mechanism, hot keys and hot partitions, sharding and partitioning, elsewhere on the site: in real incidents, in measurements, and in designs.
Pick an answer. You will see whether it is right, and why.
1. What decides which nodes store a row?
The partition key is hashed to a token, and the token range decides the replicas.
2. Three replicas. You write at QUORUM and read at QUORUM. Does the read see the write?
Two plus two is more than three, so at least one node in the read has the write.
3. What is a tombstone?
Deletes are writes too. The marker stays for gc_grace_seconds so every replica learns about the delete.
4. Why must repair run within gc_grace_seconds?
Once the tombstone is gone, a replica that never saw the delete looks like the newest copy.
How do databases actually work? From one row on disk to transactions: the words you need, PostgreSQL, MySQL and MongoDB from the files up, then Redis, Cassandra and vector search, side by side, and the query and concurrency traps.