What Cassandra Is and Why It Exists
What category of database Cassandra is, why Facebook built it in 2008, where it sits on CAP, and — most importantly — when reaching for it is (and isn't) the right call. This part is deliberately about the shape of the trade-off, not the mechanism; the ring topology, replication math, write path, and compaction internals that make the trade-off work are Parts 2 through 6.
What Category of Database Is It?
Cassandra is a leaderless, wide-column, distributed NoSQL database.
Breaking that down:
- Leaderless — there is no primary node that all writes route through. Any node can accept any write. This is the root cause of every trade-off in the system.
- Wide-column — data is stored in rows that each have a key, and each row can have a large, sparse set of columns. Rows with the same partition key are stored contiguously on disk.
- Distributed — designed from the start to span multiple machines, racks, and datacenters.
Wide-Column, in More Depth
"Wide-column" describes the storage model, and it's distinct from both relational tables and plain key-value stores:
- Sparse, per-row schema. In a relational table every row has the same fixed columns. In a wide-column store, different rows under the same partition key can have wildly different columns — one row might have 5 populated, another 5,000. There's no requirement that a column exist for every row, and nulls cost nothing because absent columns simply aren't stored.
- Rows can grow "wide." A single partition can hold an enormous, dynamically-growing number of columns — historically millions in Bigtable/Cassandra. Classic pattern: a row keyed by user ID where each column is one event or message, appended over time, instead of needing a new table or a join to a child table.
- Physical locality follows the partition key. Cassandra hashes the partition key to pick which node owns the data, and within each SSTable everything sharing that key sits in one contiguous, sorted block. A partition written over time is spread across several SSTables, one block per file, and the read merges them (Part 4c §4 shows how). Fetching "everything for user X" is one sequential read per file instead of scattered lookups across the table — this is the core reason Cassandra data models are built around "what will I query by," not around normalized relational design. You denormalize and shape rows around access patterns up front, accepting sparse/variable columns per row in exchange for that locality.
A Worked Example: Sparse Rows, Then Clustering Rows
Take a user-activity store. In a relational table every row reserves a slot for every column, populated or not, and adding a new attribute means an ALTER TABLE across the whole table:
user_id | email | phone | twitter | github | last_login
--------+---------+----------+---------+---------+-----------
u1 | a@x.com | NULL | NULL | NULL | 2026-10-01
u2 | b@y.com | 555-0101 | @bee | bee-dev | 2026-10-04In a Bigtable/HBase-style wide-column store, each row holds only the cells it actually has, and column names can themselves be data:
Row key: u1
profile:email = a@x.com
profile:last_login = 2026-10-01
<- 2 cells stored. Nothing else exists.
Row key: u2
profile:email = b@y.com
profile:phone = 555-0101
profile:twitter = @bee
profile:github = bee-dev
clicks:2026-10-04T09:00:01 = /home
clicks:2026-10-04T09:00:07 = /pricing
clicks:2026-10-04T09:01:13 = /signup
... 4,993 more click columns ...
<- 5,000 cells. Column names are timestamps.- u1 has 2 columns, u2 has 5,000, both in the same table.
- Every click is a new column (
clicks:<timestamp>), and no schema change is ever needed. In CQL terms, each click is a clustering row inside the user's partition, not a column. The "row" here is what CQL calls a partition. Cassandra before 3.0 literally stored clicks as composite column names, and the 3.0 storage engine made them real rows (mapping below). - NULLs cost nothing. u1 has no
phonecell on disk at all, so there's no NULL marker and no reserved space.
Cassandra (CQL) gets the same layout differently. CQL makes you declare columns up front, so you can't invent clicks:10:01 at write time. The value that would have been the dynamic column name moves into the primary key instead:
CREATE TABLE user_clicks (
user_id text,
ts timestamp,
page text,
referrer text,
PRIMARY KEY (user_id, ts)
-- ^^^^^^^ ^^
-- | +-- clustering key: sorts entries inside the partition
-- +----------- partition key: picks the node, groups one user's data
);| Part | Job | Analogy |
|---|---|---|
Partition key (user_id) | Hashed to pick which nodes store the data; groups everything for one user together | A folder |
Clustering key (ts) | Sorts the entries inside that partition | The pages in the folder, kept in order |
Each page in the folder is a clustering row. Insert a few clicks:
INSERT INTO user_clicks (user_id, ts, page, referrer) VALUES ('u1', '09:00', '/home', 'google');
INSERT INTO user_clicks (user_id, ts, page) VALUES ('u1', '09:05', '/about');
INSERT INTO user_clicks (user_id, ts, page) VALUES ('u2', '10:00', '/home');
INSERT INTO user_clicks (user_id, ts, page) VALUES ('u2', '10:01', '/pricing');
INSERT INTO user_clicks (user_id, ts, page) VALUES ('u2', '10:02', '/signup');
-- ... 4,997 more for u2On disk that becomes:
Partition "u1" <- one folder, stored together on the same replicas
|-- [ts=09:00] page=/home referrer=google
+-- [ts=09:05] page=/about <- no referrer cell at all
Partition "u2" <- another folder
|-- [ts=10:00] page=/home
|-- [ts=10:01] page=/pricing
|-- [ts=10:02] page=/signup
+-- ... 4,997 more, sorted by ts- u1's partition holds 2 clustering rows and u2's holds 5,000. That's the same "rows of different sizes" idea as the Bigtable example. A partition that grows this large is what wide row (or wide partition) means.
- Because entries are sorted by
ts, "u2's clicks between 10:00 and 10:05" is one bounded scan of one partition on one replica set:SELECT * FROM user_clicks WHERE user_id = 'u2' AND ts >= '10:00' AND ts < '10:05'; - Sparseness survives inside each clustering row: the second u1 insert never mentioned
referrer, so no cell was written for it.
Bigtable: row u2 -> column "clicks:10:01" = /pricing
Cassandra: partition u2 -> clustering row ts=10:01 -> page = /pricingThe physical layout is the same in both: one key holding a sorted, open-ended run of entries. CQL just presents it as a table. Part 4c §6 traces how the old "wide row" name became today's "partition".
Why Not Two Tables and a Join?
Short answer: the wide row is not better everywhere. It wins because the data is spread across many machines. And it is closer to a normal relational table than it first looks.
-
Across many machines, joins are too expensive. On one database server, joining
usersandmessagesis cheap: both tables are on the same machine, often already in memory. Once the data is split across hundreds of nodes, a user and their messages usually land on different nodes. Now a join means asking many nodes over the network and stitching the answers together. Cassandra doesn't make joins fast. It drops them completely, so you must store data so that every query can be answered from one partition. The wide row is the join, done ahead of time when you write. -
The wide row keeps related data together and in order. Every event for
user_123sits in one partition, on the same set of replicas, stored side by side on disk and sorted by the clustering key. "Last 50 messages for this user" means: go to one node, open one partition, read one sorted range. In a simple two-table design, one user's messages are scattered wherever they happened to be inserted. The same query becomes an index lookup onuser_id, then one random disk read per message. -
But a well-designed relational table can do the same thing. In MySQL/InnoDB, give the messages table the primary key
(user_id, message_time). The rows are then stored grouped by user and sorted by time, which is basically a wide row. Going the other way, a Cassandra table withPARTITION KEY (user_id), CLUSTERING KEY (event_time)is really just a child table. So the difference is less about the data model and more about a promise of how data sits on disk. What the wide row actually gives you:- No second lookup. Any user details the query needs are copied into the same partition, so one request returns everything.
- Data stays together even when sharded. With a sharded relational database you would build the routing yourself. Cassandra guarantees "everything for this key is in one partition" out of the box.
- Adding new data is cheap. A new event is one LSM write to one partition, with no separate index table to update.
Who actually uses this model, and why:
| Company | Use case | Why wide-column fit |
|---|---|---|
| Inbox Search (the original 2008 use case) | Partition key = user ID; each column = one indexed message. Rows grow indefinitely as users send messages, with no schema migration needed. | |
| Netflix | Viewing history, user profiles, A/B test data | Partition key = user/device ID; extremely high sustained write volume from every play/pause/seek event across a global user base, with multi-region replication for availability during regional outages. |
| Apple | iCloud / iMessage backend data | Massive scale (reportedly tens of thousands of Cassandra nodes) needing multi-datacenter writes with no single point of failure. |
| Feed and direct-message storage | Partition key = user ID; time-ordered columns (messages, feed entries) appended per user, read back as one contiguous range scan. | |
| Discord | Message history storage | Partition key = channel ID; messages appended as columns ordered by a time-based clustering key (Snowflake ID), so "give me the last N messages in this channel" is a single-partition read. |
The common shape across all of these: a single, well-known key (user, channel, device) that every hot-path query filters by, paired with an access pattern that's overwhelmingly "append new columns, read a contiguous range back" rather than ad-hoc joins or aggregations across keys.
Worked Example: Editing "helloo" to "hello"
An edit does not create a second row. The message keeps its primary key (channel_id, message_id), so the edit is a second version of the same cell, and the two versions can end up in different files:
SSTable-A (on disk) (42, 9001) content='helloo' @t1
Memtable (in memory) (42, 9001) content='hello' @t2
─────────────────────────────────
read result (42, 9001) content='hello' (t2 > t1)- Finding them is by key, not by search. A read checks the memtable, then every SSTable whose Bloom filter says it might hold key
(42, 9001). Each file is sorted by key, so the partition index jumps straight to it. - Merging is cell by cell: the newest timestamp wins (last-write-wins). If only
contentwas edited, the other columns still come from the older file, so the row is put together from pieces at read time. If two timestamps are equal, the larger value wins, so every node gets the same answer. - Compaction cleans up. When SSTables merge, only
'hello' @t2is written out and'helloo'is dropped. Until then it only takes up disk space. - Replicas follow the same rule. If one replica missed the edit, a QUORUM read sees both versions, returns the newer one, and read repair fixes the stale replica.
This is why the new value must not depend on the old one. "Set to 'hello'" merges cleanly. "Add 1 to likes" doesn't: two writers would both read 5 and both write 6. That's what counters and lightweight transactions (Paxos) are for, and why they're slower. Catch: "newest" means the highest timestamp (from the coordinator's or client's clock), not the write that really happened last, so clock skew can let an older write win. Keep clocks in sync with NTP.
Origin Story — Why Facebook Built It in 2008
Facebook needed to power the Inbox Search feature — the ability to search your own message history. The constraints were:
- Massive write throughput: millions of users constantly sending messages
- High availability: inbox search could not go down even if a datacenter failed
- Geographic distribution: data needed to live close to users worldwide
- Predictable low latency at scale: not fast-on-average but consistently fast
No existing system fit. MySQL couldn't handle the write throughput. HBase required ZooKeeper coordination overhead. Amazon's Dynamo paper (2007) had proven leaderless replication was viable. Google's Bigtable paper (2006) showed wide-column storage was efficient for sparse data. Facebook combined both ideas into Cassandra, open-sourced it in 2008, and donated it to Apache in 2009.
Where It Sits on the CAP Theorem
CAP says a distributed system can guarantee at most two of:
| C — Consistency | Every read gets the most recent write |
|---|---|
| A — Availability | Every request gets a response, even during failures |
| P — Partition tolerance | The system keeps working even when network splits occur |
Partition tolerance is not optional in a real distributed system — networks do split. So the real choice is C vs A when a partition happens.
The real choice is never all three at once — it's C vs. A, and only the instant a partition actually happens. Cassandra picks A: Availability + Partition tolerance.
Clarifying What Each Letter Actually Means
- Consistency is not "replication working properly." Replication is the mechanism that moves a write from one replica to another; consistency is the guarantee about what a read returns — specifically, that every read reflects the most recent write, no matter which replica answers it. Replication can be actively happening (eventually propagating the write to every replica) while consistency is still violated, because for some window of time different replicas disagree on the current value.
- Partition tolerance is not "connectivity breaking down" in general. It specifically means a network split: the cluster divides into two or more groups where nodes within a group can still reach each other, but the groups cannot reach each other. Nothing goes fully down — replicas on each side are still up and can still serve requests. What breaks is cross-group replication: a write on side A physically cannot reach the replicas on side B until the network heals.
That's the real dilemma CAP describes: when a split happens, each isolated side must choose between refusing to answer until it can confirm it has the latest data from the other side (choosing C), or answering immediately from what it has locally, accepting the answer might be stale relative to the other side (choosing A). Cassandra picks the second option.
What This Means Concretely for Application Code
When a network partition isolates some replicas, Cassandra will:
- Still accept writes to any available replica
- Still return reads from available replicas, even if they might be stale
It will not refuse requests to preserve a consistent view.
One-Sentence Comparisons
| System | Contrast |
|---|---|
| PostgreSQL (RDBMS) | Single-node or primary/replica; full ACID transactions and arbitrary joins; vertically scaled; correct choice when your data model is relational and your scale fits one machine or a handful of replicas. |
| DynamoDB (managed leaderless) | Same AP leaderless model as Cassandra but fully managed by AWS; you pay for operational simplicity with vendor lock-in and less control over compaction, data locality, and consistency tuning. |
| HBase (Hadoop-backed) | Also wide-column but uses HDFS underneath and requires ZooKeeper for coordination; stronger consistency guarantees (single leader per region); better for analytics and sequential scans, worse for low-latency random reads. |
| ScyllaDB (Cassandra-compatible rewrite) | Drop-in Cassandra replacement written in C++ using a shard-per-core model; dramatically lower latency and higher throughput per node; same data model and CQL; the correct choice if you're starting a new Cassandra-compatible deployment and don't have existing Cassandra operational muscle. |
When (Not) to Reach for Cassandra
When to Reach for Cassandra
Reach for Cassandra when all of these are true:
- Write throughput is high and sustained (hundreds of thousands of writes/second)
- Reads are by a known, narrow key — you can express every query as "give me rows for this partition key"
- You need multi-datacenter replication or geographic distribution
- You can tolerate eventual consistency in exchange for availability
- Your data has a natural time-series or append-heavy shape
Canonical Examples
| Example | Partition key | Why it fits |
|---|---|---|
| IoT sensor data | device ID | Relentless append rate from every sensor; reads are "recent readings for this device"; old data expires via TTL (TWCS-friendly). |
| User activity feeds | user ID | Events appended per user, read back as one contiguous time-ordered range scan. |
| Time-series metrics | metric name + time bucket | Write-once, read-recent; whole windows expire together, so old SSTables are dropped as files. |
| Messaging inboxes | user / channel ID | The original Facebook use case; "last N messages" is a single-partition range read, and edits are just upserts (Part 4). |
| Recommendation counters | item / user ID | High-volume increments via counter columns; approximate-tolerant, availability matters more than exactness. |
| Audit logs | entity ID + time bucket | Append-only by definition, queried by known key and time range, retained then expired in bulk. |
When Not to Reach for Cassandra
| Situation | Use instead |
|---|---|
| You need ACID transactions or foreign key constraints | PostgreSQL |
| You need arbitrary ad-hoc queries, joins, or aggregations | PostgreSQL / BigQuery / Snowflake |
| Your scale fits on one or two machines | PostgreSQL |
| You need strong consistency without tuning every operation | CockroachDB / Spanner / FoundationDB |
| Reads are scans and aggregations across many partitions, not lookups inside one | Iceberg / Delta Lake on object storage, queried by Spark / Trino / Databricks (Part 10) |
| Retention is years but the read rate is near zero (compliance, cold audit history) | Iceberg / Delta — object storage is ~20–50× cheaper per byte than RF=3 on NVMe |
| Your access patterns are unknown at modeling time | PostgreSQL first — migrate later if needed |
| You need a managed service and don't want to operate a cluster | DynamoDB or a managed Cassandra-as-a-service |