Quick Reference · wide-column distributed database

cassandra cheat sheet

Cassandra flips the relational habit: you model tables around your queries, not your entities. Every table nests the same way — a keyspace holds tables, a partition key decides which node stores a row, and a clustering key sorts rows inside that partition. Learn that ladder once and CQL stops feeling like SQL that's missing pieces.

cqlsh / session schema · DDL write · DML query · read destructive most common

Distilled & cross-checked across: cassandra.apache.org/doc · docs.datastax.com · baeldung.com · javaguides.net · scylladb.com/glossary · pythian.com

The data model — how a row finds its place
CLUSTER · a ring of nodes KEYSPACE replication strategy + factor "where & how many copies" TABLE columns + a PRIMARY KEY PRIMARY KEY = ( partition key ) , clustering key… partition key → which node clustering key → sort order hash(pk) → token PARTITION all rows sharing one partition key the unit of storage & the unit you query row · ck = 2026-08-01 ▸ … row · ck = 2026-08-02 ▸ … row · ck = 2026-08-03 ▸ … ↕ sorted on disk by clustering key → range scans within a partition are cheap replicate ×RF TOKEN RING A B C D E F token owned by B, C, D RF=3 → 3 replicas, no master
01cqlsh & Sessionthe shell
02Keyspacesreplication container
03Tablescolumns + keys
04Primary Key Anatomythe whole game
05Insert & Updatewrites are upserts
06Select & Queryquery-first rules
07Delete & Truncatewrites tombstones
08Data Typescolumn types
09Collections & UDTnested data
10Batchatomic, not faster
11Indexes & Viewsquery other columns
12Consistency Levelstunable per query
13Roles & SecurityDCL
14Ops · nodetoolrun on a node
The WHERE Ruleswhy queries fail

How it works under the hood

Four pictures that explain most of Cassandra's behaviour — the write path, why quorums give strong consistency, how the ring spreads data, and what a delete really does. Based on the Apache Cassandra and DataStax architecture docs.

The write path

A write is durable the moment it hits the commit log and memtable — SSTables are flushed later and never modified in place.

write Commit Log disk · durability Memtable memory · sorted flush SSTables immutable compacted later

Why R + W > RF works

With RF=3, a QUORUM write hits 2 replicas and a QUORUM read asks 2 — the sets must overlap, so a read always sees the latest write.

R1 R2 R3 WRITE = 2 READ = 2 R2 = overlap

Consistent hashing & the ring

The partition key hashes to a token; the node owning that token range stores it, then copies to the next RF−1 nodes clockwise. No shard master.

N1 N2 N3 N4 hash(key) = token 82 → N2 owns, N3,N4 copy 0 … 2⁶⁴

A delete is a write

Deletes append a tombstone marker; the data only truly vanishes after gc_grace_seconds (default 10 days) and a compaction — so mass deletes bloat reads.

row live ✝ tombstone DELETE reads still scan it gc_grace purged compaction

Worth memorizing

query-firstdesign tables for reads — one table per query, denormalize freely
no JOINs, no GROUP BYno server-side aggregation across partitions — do it at write time
INSERT = UPDATEboth are upserts; last write (by timestamp) wins
partition key firstevery efficient WHERE must pin the full partition key
ALLOW FILTERINGa modelling smell, not a feature — almost never in prod
RF ≠ CLRF = copies stored (schema); CL = copies awaited (per query)
delete ⇒ tombstonedeletes cost reads later; prefer TTL for expiring data
keep partitions smallbounded rows & < ~100 MB — the #1 modelling mistake