Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Explain the data model of a wide-column store such as Apache Cassandra: partition key, clustering columns, and why queries must usually include the partition key.

In Cassandra every table has a primary key made of a partition key and optional clustering columns. The partition key is hashed to decide which nodes store the row, and the clustering columns sort the rows inside that partition, so a query that gives the partition key goes to a few replicas and reads one sorted slice. A query without the partition key would have to ask every node, which Cassandra refuses unless we add ALLOW FILTERING, a warning sign; so we design one table per query pattern and duplicate data, which cheap writes make affordable.

Why this question is asked

Developers coming from relational databases often try to use Cassandra like PostgreSQL with a different syntax, and the first query that filters on a normal column fails with a confusing error. The reason is that Cassandra's data model is built around how rows are distributed across a cluster, and the primary key decides that distribution. Interviewers ask this question to see whether we understand the model well enough to design tables that scale. In this answer, we will recap the primary key, see how the partition key places data on nodes, how clustering columns sort it, why queries need the partition key, and why we design one table per query and accept duplication.

1A Quick Recap of the Primary Key

Cassandra is called a wide-column store because one partition can hold many rows, each with its own columns, sorted on disk. The primary key has two parts. The partition key, the first part, names the partition a row belongs to. The clustering columns, the rest of the key, identify a row within its partition and define the order in which rows are stored.

SQL
CREATE TABLE orders_by_customer (
customer_id uuid,
order_date date,
order_id timeuuid,
total decimal,
status text,
PRIMARY KEY ((customer_id), order_date, order_id) -- partition key, then clustering columns
) WITH CLUSTERING ORDER BY (order_date DESC, order_id DESC);

Here customer_id is the partition key, so all orders of one customer live together in one partition, and order_date and order_id are clustering columns, so inside the partition orders are stored newest first. The double parentheses make the partition key explicit; with a composite partition key we would write ((customer_id, year), order_date, order_id).

2How the Partition Key Places Data on Nodes

Cassandra hashes the partition key with a partitioner, Murmur3Partitioner by default, into a number called a token. Each node owns ranges of tokens, and the replication factor, for example 3, decides how many nodes hold a copy: the node that owns the token and the next ones around the ring, chosen per data centre. So every partition lives on exactly three nodes, and any node can work out which ones from the key alone.

This is what lets Cassandra scale. Adding nodes splits token ranges, and partitions spread evenly as long as there are many partition keys with similar sizes. It also explains the main rule of modelling: if we know the partition key, the coordinator, the node that receives our query, knows exactly where to go.

Step throughA read that gives the partition key
ClientCoordinatorReplica 1Replica 2Replica 3
SELECT ... WHERE customer_id = c42
hash c42 -> token -> replicas 1, 2, 3
read slice of partition c42
read slice of partition c42
rows, sorted by order_date
rows
result at LOCAL_QUORUM

7 messages in order. Play them, or step through them one at a time.

Replica 3 is not needed at LOCAL_QUORUM with replication factor 3: two answers suffice.

3How Clustering Columns Sort Rows

Inside a partition, rows are stored sorted by the clustering columns, in the order the table declares. That makes range queries on clustering columns cheap: 'the last 10 orders of customer c42' or 'orders of c42 in March' are contiguous slices that Cassandra reads from the start of the range until the limit is reached.

SQL
SELECT order_id, total FROM orders_by_customer
WHERE customer_id = c42 LIMIT 10; -- newest 10, one sorted slice
SELECT order_id, total FROM orders_by_customer
WHERE customer_id = c42
AND order_date >= '2026-03-01' AND order_date < '2026-04-01'; -- range on clustering column
SELECT * FROM orders_by_customer WHERE status = 'SHIPPED';
-- InvalidRequest: Cannot execute this query as it might involve data filtering and thus may
-- have unpredictable performance. If you want to execute this query despite the performance
-- unpredictability, use ALLOW FILTERING

Notice the third query. It does not give the partition key, so Cassandra cannot know which nodes hold shipped orders. Clustering columns also have rules: we can filter on them only in order, so we cannot restrict order_id without restricting order_date first.

4Why Queries Must Include the Partition Key

Without the partition key, the only way to answer the status query is to ask every node to scan every partition and filter rows one by one. On a cluster with 30 nodes and billions of rows that is a full table scan, and its cost grows with the data. Cassandra refuses such queries by default and tells us to add ALLOW FILTERING if we really mean it. Adding it is almost always a warning sign: the query may work on a small test table and then time out in production.

There are narrow exceptions. ALLOW FILTERING is acceptable when the partition key is given and we filter a small partition further on a non-key column. Secondary indexes and storage-attached indexes exist too, but they still have to consult many nodes for a query without a partition key, so they suit low-volume lookups, not the main access paths; check your version, since index features have changed in Cassandra 5.

5One Table per Query, and Why Duplication Is Fine

Since every efficient query needs its partition key, we design tables from the queries, not from the entities. If the application needs orders by customer and also orders by status for a warehouse screen, we create two tables, orders_by_customer and orders_by_status_day with partition key (status, day), and write each order to both. There are no joins, so each table holds everything its query returns.

That duplication is affordable because writes in Cassandra are cheap. A write is appended to the commit log on disk for durability and placed in an in-memory table called the memtable; nothing is read or updated in place. When the memtable fills, it is flushed to disk as an immutable SSTable, and background compaction later merges SSTables. Writing a row twice costs two fast appends, far less than a scan at read time.

Step throughThe write path that makes duplication cheap
  1. Commit logsequential append, for durability
  2. Memtablein-memory, sorted by key
  3. SSTablesimmutable files flushed from memtables
  4. Compactionmerges SSTables in the background

4 layers, from the top down. Step through them one at a time.

6Follow-up questions

What happens if a partition key has too few distinct values?

Data is spread over too few partitions, so a few nodes do all the work and partitions grow without limit. A partition key such as status with three values would put every order in three partitions. We add a bucket, such as the day, to the partition key so the number of partitions grows with time.

How do you choose the consistency level for reads and writes?

With replication factor 3, LOCAL_QUORUM for both reads and writes means two replicas in the local data centre must answer, so a read always overlaps the latest acknowledged write. ONE is faster but may read stale data. The level is chosen per query in the driver.

Can you update a clustering column?

No. The clustering columns are part of the primary key, so changing one means a different row. We delete the old row and insert the new one, ideally in a logged batch if both belong to the same table and must stay together.

7Conclusion

In this answer, we saw that a Cassandra primary key is a partition key plus clustering columns. The partition key is hashed to a token that decides which replicas hold the row, and the clustering columns keep rows sorted inside the partition, so queries with the partition key read one sorted slice from a few replicas. Queries without it would scan every node, which is why Cassandra demands ALLOW FILTERING, and why we model one table per query and accept duplicated data, which the append-only write path makes cheap.

What to say in the interviewAbout 80 seconds aloud

Open with

In Cassandra the primary key has two parts. The partition key is hashed by the partitioner into a token, and that token decides which nodes, according to the replication factor, store the partition.

Then, if they want more

The clustering columns then sort the rows inside the partition, so with orders_by_customer partitioned by customer_id and clustered by order date descending, all of a customer's orders sit together, newest first. A query that gives the partition key goes straight to the replicas that own it and reads a contiguous slice, which is fast whatever the cluster size.

A query that does not give it would have to contact every node and scan every partition, so Cassandra rejects it unless you add ALLOW FILTERING, and seeing that in production code is a warning sign.

That is why we design tables from queries: one table per access pattern, such as orders by customer and orders by status and day, and we write the same data into each, because there are no joins.

Duplication is acceptable because writes are cheap: they go to the commit log and memtable, get flushed to immutable SSTables, and compaction merges them in the background.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Redis documentation, MongoDB manual
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain the data model of a wide-column store such as Apache Cassandra: partition key...": https://scrivio-interview-library.netlify.app/databases/nosql-fundamentals/c4e3199dc4/