Home›Learn›Cassandra 2: how it stores your data
Cassandra · Chapter 2

How Cassandra stores your data

Where does a row go when there is no primary?

The ring, the commit log, memtables and SSTables. Then one write, end to end.

The architecture: a ring of equal nodes

There 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:

Cassandra: architecture

Write path on each replica

Processone Java process per node · any node can coordinate a request · the partition key's hash picks the replicas
→
Memorya memtable per table, holding recent writes in sorted order · key cache · a bloom filter per SSTable
→
Diskcommitlog/ segments · data/<keyspace>/<table>/ SSTables (Data.db, an index, Filter.db, Statistics.db) · hints/
Who does what: The coordinator hashes the partition key to a token and sends the request to the replicas that own that token. Each replica appends to the commit log, adds the write to its memtable and acknowledges. Memtables flush to immutable SSTables, and compaction merges SSTables and finally drops deleted data.
Where the data lives

A log, a memtable, and files that never change

PlaceWhat it holdsWhat to watch
commitlog/every write, appended before it is acknowledgedcommitlog_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.
Memtablerecent writes, sorted, in memoryFlushed to an SSTable when full. Big memtables mean more commit log to replay after a crash.
SSTablesimmutable sorted files; a read may have to look in severalSSTables per read in nodetool tablehistograms. Compaction keeps the count down.
Tombstonesmarkers 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.
Follow it

Follow one write at QUORUM, and one node down

Replication factor 3, one chat message, written at QUORUM. Step through it, then tick the box.

A replica is down and you write at QUORUM with three replicas. Does the write succeed?

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.

Next · chapter 3High availabilityReplicas and consistency, no failover← Chapter 1: Why Cassandra
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