A guide to Apache Cassandra: Query-First Modeling and Tunable Consistency

How to work through this course

Seven modules, about ninety-five hours. It is the longest course in the database programme after Oracle, and the difficulty is concentrated in two places: a data modelling discipline that contradicts everything you were taught about databases, and an operational contract that is easy to break silently.

Build three nodes in Module 1, not one. Consistency levels, replication, hints, repair and node replacement do not exist on a single node, and every one of them is examined. Docker Compose is enough; ccm is better if you want two datacentres on one machine. Budget the memory - Cassandra wants 2 GB of heap per node, and a cluster that is swapping will teach you the wrong lessons about latency.

Two experiments are worth more than the rest of the course combined.

The first is the consistency table in Module 3: write at ONE and read at ONE in a loop and count the misses, then do QUORUM/QUORUM and count zero. Fill in every combination with its miss rate and its latency. That table turns R + W > RF from an inequality you can recite into a design tool you can use, and you will reuse it.

The second is the queue anti-pattern in Module 4: build a table used as a queue, drive it for a while, and watch read latency climb from two milliseconds to a timeout as tombstones accumulate at the front of the partition. It takes an afternoon and it inoculates you against a whole family of production incidents - because the shape of the mistake (delete-heavy access to a range you then read) appears in many designs that do not look like queues.

Two things to unlearn, and they are the hard part. The first is normalisation: here, five tables holding the same data five ways is correct, and resisting it produces a schema that scatter-gathers. The second is the idea that you can query your data however you like later. You cannot, and the cost of discovering a missing access pattern is a new table and a backfill - so the query list genuinely comes first, in a file, numbered.

Respect the gc_grace_seconds contract from the first table you create. Tombstones must outlive your repair interval, or deleted data comes back. People reduce the grace period to control tombstones - which works, and resurrects data months later, long after anyone connects the two events. Set the grace period from your repair schedule, alert on repair recency, and treat a repair that has not completed as an incident.

Run NTP and monitor clock offset, and think of it as a correctness requirement. Cassandra resolves conflicts by timestamp, so a node whose clock is seconds fast silently wins conflicts it should lose, and nothing reports it. Of all the operational facts in this programme, this is the one most likely to cause data loss that nobody ever diagnoses.

Use TRACING ON constantly while learning. It shows the coordinator, the replicas contacted, the SSTables merged and - the important one - the live rows against tombstone cells. Most Cassandra performance questions are answered by one trace, and the habit of reading them is what distinguishes someone who operates Cassandra from someone who uses it.

What to skip on a first pass. CDC and change data capture. The nodetool commands beyond status, tablestats, tablehistograms, compactionstats, tpstats, netstats, repair, snapshot and drain. SASI indexes. Transient replication. The internals of gossip and the failure detector. Thrift and the legacy cassandra-cli, which you will still find in old documentation. And ACID transactions via Accord, which is genuinely interesting, recent, and not where to start.

Where to look things up. The official documentation is solid and its Data Modeling section is the right starting point. DataStax Academy's free courses cover the same ground well. Cassandra: The Definitive Guide is good on architecture. And the DataStax driver documentation is worth reading properly, because the driver's retry, idempotence and speculative execution policies are part of your correctness story and not a configuration afterthought.

One closing thought. Cassandra asks more of you than any other database in this programme - it will not plan your query, will not enforce your foreign keys, will not warn you about a growing partition, and will not tell you when a clock made you lose data. In exchange it will keep writing when a datacentre goes dark, and it will do that at a scale and a predictability very little else matches. Whether that is a good trade depends entirely on what you are building, and the most valuable thing this course can give you is the ability to say which situation you are in - and to say no when the answer is a relational database.

cassandra database