Home›Learn›Cassandra 1: why Cassandra
Course · Spread the dataLesson 20 of 330 read

Cassandra

How does Cassandra take so many writes, and why is it so picky about queries?

Explained clearly

What Cassandra is, and why it exists

1

The problem

Some systems write all day and never stop: messages, events, sensor readings. Billions of rows, across data centers, with no single server allowed to be the bottleneck or the point of failure.

2

What it is

Cassandra is a wide-column database built as a ring of equal nodes. There is no primary. The partition key is hashed to a token, the token decides which nodes own the row, and each row is stored on several of them (the replication factor). Each query chooses how many copies must answer: its consistency level.

3

Follow one write

  1. The app sends a write to any node. That node coordinates it.
  2. The coordinator hashes the partition key and sends the write to the replicas that own it.
  3. Each replica appends it to its commit log and its in-memory memtable, then answers.
  4. At QUORUM with three replicas, two answers are enough. Memtables flush to immutable SSTable files later, and compaction merges them.

For your app: writes stay fast and available even with a node down, if you design tables around your queries.

4

What to watch

  • Model by query. There are no joins; each table serves one read pattern through its partition key.
  • Large partitions and tombstones make reads slow. Deletes are writes that are cleaned up later.
  • Repair keeps replicas in step. Skipping it lets deleted data come back.

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.

Cassandra: in one line

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 query
Where it fits in a design

Endless writes, read by key

Use it for

Not for

Your turn

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.

Show my answer

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.

Next · chapter 2How it stores your dataThe ring, commit log and SSTables
Connected

Where this shows up

The same mechanism, hot keys and hot partitions, sharding and partitioning, elsewhere on the site: in real incidents, in measurements, and in designs.

Check yourself · 4 questions

Check yourself

Pick an answer. You will see whether it is right, and why.

1. What decides which nodes store a row?

2. Three replicas. You write at QUORUM and read at QUORUM. Does the read see the write?

3. What is a tombstone?

4. Why must repair run within gc_grace_seconds?

One database decision a weekA short email each week: one real decision, the trade-off, and the command to check it. Unsubscribe in one click.

Part 1 of 4 · Learn · 56 pagesAll pages

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.

Start 1: the basicsStart 2: ten conceptsStart 3: how a query travelsStart 4: napkin mathThe courseShort videosPostgreSQL 1: why PostgreSQLPostgreSQL 2: how it stores your dataPostgreSQL 3: what happens on every writePostgreSQL 4: high availability with PatroniPostgreSQL 5: running it as a DBREPostgreSQL 6: when it breaksPostgreSQL on Kubernetes: CloudNativePGMySQL 1: why MySQLMySQL 2: how it stores your dataMySQL 3: what happens on every writeMySQL 4: high availability with InnoDB ClusterMySQL 5: running it as a DBREMySQL 6: when it breaksMySQL failover with OrchestratorMySQL on Kubernetes: the Percona operatorsMongoDB 1: why MongoDBMongoDB 2: how it stores your dataMongoDB 3: what happens on every writeMongoDB 4: high availability with replica setsMongoDB 5: running it as a DBREMongoDB 6: when it breaksMongoDB on Kubernetes: the Percona operatorB-tree and LSM treeRedis 1: why RedisRedis 2: how it stores your dataRedis 3: high availabilityRedis 4: running it as a DBRERedis 5: when it breaksCassandra 1: why CassandraCassandra 2: how it stores your dataCassandra 3: high availabilityCassandra 4: running it as a DBRECassandra 5: when it breaksVector databases 1: why vector searchVector databases 2: how it stores your dataVector databases 3: high availabilityVector databases 4: running it as a DBREVector databases 5: when it breaksDatabase familiesEngines side by sideQueries that look fine and are notLost updates and write skewMany servers 1: keep a copy runningMany servers 2: who is the leaderMany servers 3: CAP as settingsMany servers 4: unique IDsMany servers 5: split the dataMany servers 6: across servicesMany servers 7: a thousand databasesStaff path, zero to architect