Apache Cassandra Interview Questions: Keys and Quorum

Work through the Cassandra questions that decide technical rounds: partition keys, quorum arithmetic, denormalisation and tombstones, each with a worked example and a four-sentence answer.

By AI Interview AssistantPublished 13 min read

Apache Cassandra interview questions are design-judgment prompts, not a feature quiz. Expect to choose a partition key, defend a consistency level, explain what denormalisation costs and say when Cassandra is the wrong tool. Answer in one order every time: the access pattern, the design choice, the cost you accept, the alternative you rejected. That order is what separates someone who has run a cluster from someone who has read about one.

Why the query comes before the table

When a Cassandra question starts, answer with one table, one query and one partition key before you discuss anything else. A table exists to serve a query, so the query comes first.

The common failure is describing Cassandra as a SQL database that scales, then drawing a normalised schema with foreign keys between tables. Cassandra has no joins. A design that needs one table per entity and a join at read time cannot run on the cluster you were asked to design.

Write the query first, then the table, then the key. If you can write the WHERE clause, you already know the primary key, and the rest of the answer follows from it.

Partition key design questions and how to defend a choice

Partition-key questions come up first in most Cassandra interviews, and they reward practice more than any other part of your prep. Take a chat application that stores messages by conversation. The query is "the last 50 messages in this conversation, newest first". Here is the table:

CREATE TABLE messages_by_conversation (
  conversation_id uuid,
  sent_at timestamp,
  message_id uuid,
  sender_id uuid,
  body text,
  PRIMARY KEY ((conversation_id), sent_at, message_id)
) WITH CLUSTERING ORDER BY (sent_at DESC, message_id ASC);

SELECT * FROM messages_by_conversation
WHERE conversation_id = ?
LIMIT 50;

The partition key is conversation_id, so every message in one conversation lands on one node set and the read is a single-partition read. sent_at DESC puts the newest rows first, so the LIMIT 50 stops early instead of scanning the partition. message_id breaks ties when two messages share a timestamp.

Choosing sender_id alone would be the mistake. Keying on sender_id puts every message one account sends into a single partition, so a very active account concentrates its writes on the nodes holding that partition while the rest of the cluster carries less load. That is a hot partition, and it is a failure mode worth naming up front.

A likely follow-up is "what if one partition grows too big?" Answer with bucketing: add a time window to the key, for example PRIMARY KEY ((conversation_id, month_bucket), sent_at, message_id). Each month of a conversation becomes its own partition, so writes spread out and compaction works on smaller units. The cost is real: reading the last 50 messages across a month boundary means two queries and a merge in the application, and any query that does not know the bucket needs a full scan of buckets. Name that cost as part of the answer.

A second mistake to avoid: picking a key for uniqueness rather than for the read pattern. A high-cardinality key such as message_id spreads data evenly, but you can never ask "give me this conversation" without ALLOW FILTERING, which scans every node and is a design smell, not a fix.

Quorum arithmetic you can say out loud

Quorum questions reduce to one inequality, so answer them with the arithmetic. With replication factor RF, a write acknowledged by W replicas and a read served by R replicas gives read-your-write when W + R > RF, because the two replica sets must overlap in at least one node that has the latest value.

Work it with numbers. Assume RF = 3, a write at QUORUM (W = 2) and a read at QUORUM (R = 2):

Assume replication factor RF = 3
Assume write consistency W = 2 (QUORUM)
Assume read consistency  R = 2 (QUORUM)

Overlap rule: W + R > RF
2 + 2 = 4 > 3  -> at least one replica in the read set holds the latest write

Variant: W = 1, R = 1
1 + 1 = 2, not > 3 -> the read set may miss the write entirely

Write the inequality on the whiteboard if there is one. It shows the reasoning rather than a memorised answer, and it lets you answer variants on the spot.

ONE is defensible when a lost write is cheap: application logs, metrics, click events where you would rather drop a point than slow the ingest. What you give up is any guarantee that the next read sees the write, so a dashboard can lag and a user can refresh and see stale data.

LOCAL_QUORUM matters when the cluster spans data centres. A plain QUORUM counts replicas across all of them, so a write can wait on a remote centre and pay cross-datacentre latency on every request. LOCAL_QUORUM requires a majority only within the local centre, which keeps latency predictable; the cost is that a write acknowledged at LOCAL_QUORUM has not necessarily reached any remote centre, so if the local centre is lost permanently before repair or hinted handoff reaches the remote replicas, those writes may never arrive.

The trap question is "is QUORUM strongly consistent?" The honest answer: W + R > RF guarantees overlap only when every replica in both sets responds. If a replica holding the latest write is down and the coordinator still reaches the required count from other replicas, the read can return an older value; hinted handoff narrows that window but does not close it. If fewer than two replicas respond, the coordinator cannot satisfy the level and the read fails or times out rather than returning a value. At ONE or LOCAL_ONE it returns whatever the single replica it reached holds, which may be stale. Say that, and say which failure you would test for.

Denormalisation: the cost you must name

Denormalisation is where a Cassandra answer most often slips: you describe the tables and forget the cost. The chat example needs a second query: "this user's recent messages across all conversations". Cassandra cannot join, so you write the same message to a second table with a different key:

CREATE TABLE messages_by_user (
  user_id uuid,
  sent_at timestamp,
  conversation_id uuid,
  message_id uuid,
  body text,
  PRIMARY KEY ((user_id), sent_at, message_id)
) WITH CLUSTERING ORDER BY (sent_at DESC, message_id ASC);

Keeping the two tables in sync is application work, in plain steps:

  1. Build both rows in memory from the same message object, so the values cannot diverge at write time.
  2. Write to the conversation table first, because that is the read path users notice.
  3. Write to the user table second, and treat a failure as retryable rather than fatal.
  4. Record the write in a durable queue or outbox if the second write must not be lost, and replay it on failure.
  5. Run a periodic repair job that compares a sample of rows and rewrites the missing side.

The honest answer to "how do you handle updates?" is that you write to both tables, accept a window where they disagree, and name that window. If the second write fails and the retry is delayed, the user table is stale for as long as the retry takes — seconds in the normal case, longer if the queue backs up. A logged batch makes the statements atomic in the sense that the coordinator writes a batch log first and replays it if it dies mid-batch, so the batch is not left half-applied by a coordinator failure. It gives no isolation, so a reader can see one statement applied and not the other, and it does not guarantee delivery to a replica that stays down past hinted handoff. It is not a multi-row transaction, and you should not present it as one.

A strong answer names the consistency window and the repair path, rather than claiming the database synchronises the tables for you. The rejected alternative is worth one sentence: a single table with a secondary index or ALLOW FILTERING avoids the duplicate write but turns every read into a scatter across nodes.

Compaction and tombstones without hand-waving

Cassandra writes are append-only. A write lands in a memtable in memory, is flushed to an immutable SSTable on disk, and over time many SSTables accumulate. Compaction merges them, keeps the newest version of each row, and drops data that is no longer needed. Without compaction, reads would have to check every file.

Deletes are writes too. A delete records a tombstone, a marker that says "this row is gone", which must survive long enough for every replica to see it. That is what gc_grace_seconds controls: the tombstone is kept for at least that long before compaction may purge it.

Walk through two cases. Every number below is a labelled assumption, not a measured default:

Assume 10,000 rows deleted, all in one partition
Assume gc_grace_seconds = 864000 (10 days, chosen for this example)
Assume each tombstone costs about 1 microsecond to skip on read
Assume the client read timeout is 5 seconds

Case (a): one range delete of 10,000 rows inside that partition
A range delete writes one range tombstone per partition it covers, so
deleting inside a single partition is one marker. It is flushed and
later merged like any other write. One range delete is far cheaper
than 10,000 separate row deletes, but a range that spans many
partitions writes one marker per partition, so the count grows with
the number of partitions touched, not with the number of rows.

Case (b): the same 10,000 rows deleted one by one
Each statement writes its own row tombstone, so the same partition
now carries 10,000 tombstones, plus the round trips to send them.

10,000 x 1 microsecond = 0.01 seconds of skipping per cycle
That is small on its own. Now assume the same partition is rewritten
500 times, each cycle deleting 10,000 rows one by one:

This figure applies to case (b) only; case (a) would carry roughly
500 markers, one per cycle.

500 x 10,000 = 5,000,000 tombstones
5,000,000 x 1 microsecond = 5 seconds of skipping
5 seconds is at the 5-second client timeout, so the read can fail

The per-tombstone cost, the cycle count and the timeout are illustrative: a real cluster's numbers will differ, so the arithmetic shows the shape of the risk, not a prediction. The design consequence is to model deletes as writes where you can: mark a row deleted with a status column and filter it out in the application, or partition by time so an old bucket can be dropped whole rather than row by row. Size partitions so compaction stays predictable, and if you must delete in bulk, prefer one range delete over many separate statements, and watch the tombstone count rather than firing repeated deletes at a large partition.

When Cassandra is the wrong answer

A common Apache Cassandra interview questions theme is knowing when to say no. Cassandra is a poor fit for ad-hoc queries you cannot predict, for joins across entities, for strong multi-row transactions, and for small datasets where a single relational server is simpler to run and back up. None of those is a criticism of the database; they are different problems.

The comparison to offer is short: Cassandra for high write throughput against a fixed set of known queries, spread across many nodes; a relational store for flexible querying and transactions over related data. Then place your own case on that line.

Phrase it without sinking your candidacy: "I would use Cassandra here because the access pattern is fixed and the write volume is high; if the product needed ad-hoc reporting over the same data, I would push back and propose a separate store for that." That sentence shows judgment, which is the quality a design round is testing for.

Apache Cassandra interview questions: pattern, choice, cost, alternative

The Apache Cassandra interview questions that decide a round are the ones where you choose and defend, so every answer follows the same four sentences. Using the chat table above:

  1. Pattern: "The query is the last 50 messages in a conversation, newest first."
  2. Choice: "So the partition key is conversation_id, with sent_at descending as the clustering column."
  3. Cost: "One very active conversation can make a hot partition, so I would bucket by month and accept a two-query merge at the boundary."
  4. Rejected alternative: "I would not key on sender_id, because a single popular sender concentrates the writes, and I would not rely on ALLOW FILTERING to fix it."

Then stop and let the follow-up set the next question. If you do not know a tuning detail, say what you would measure and how you would test it rather than inventing a number. "I would watch read latency and tombstone counts under load before choosing a compaction strategy" is a stronger answer than a confident figure you cannot defend.

For the wider reasoning these questions sit inside, see distributed systems trade-off answers and data engineering trade-off questions. Practising the four sentences aloud is covered in answering technical questions out loud.

Frequently asked questions

Do I need to know CQL syntax in detail for a Cassandra interview?

Enough to write a table and the query it serves, not every function. Expect to produce a CREATE TABLE with a composite primary key and a SELECT that names the partition key. Small slips are usually forgiven; what stands out is a schema whose key does not match the query you were given.

How do I answer if I have used Cassandra only through a managed service?

Name what the provider decided for you and what you still chose. Before the interview, list the three settings you did touch — table design, consistency level, TTL — and one you did not, and say so plainly when asked. Then describe one thing the provider hid from you — a repair, a compaction strategy, a topology change — and how you would find out what it does before relying on it.

What if the interviewer asks about a Cassandra version I have not used?

Anchor on the version you know and check the rest rather than guessing. One concrete move: look up the feature in that release's notes or the project's changelog before you rely on it, and say that is what you would do. Design reasoning carries most of the answer; a version-specific setting is a detail you can verify in a minute.

Should I mention Cassandra experience on my resume if I only ran a small cluster?

Yes, described at the scale you actually ran. Say how many nodes, what you stored and which decisions were yours, such as a table design, a consistency level or a compaction setting. A small cluster you operated honestly is stronger evidence than a large one you only read about, and it gives the interviewer real follow-ups to ask.

Facing a Cassandra design round? See how AI Interview assistant works.

A wall of pigeonhole shelves sorted into separate sections by wooden dividers, with a hand placing a folder into one section

12 min read

Data Partitioning System Design Interview: Choosing a Key

A spoken structure for choosing a partition key in interviews: start from the access pattern, name the trade-off you accept, and handle the follow-up questions.

  • Data partitioning system design interview
  • Data partitioning interview explanation
An engineer at a whiteboard sketching a database split into several shards with arrows to separate server icons while a colleague watches

13 min read

Database Sharding System Design Interview: Lead With the Why

Learn how to explain database sharding in a system design interview by leading with the problem, choosing a shard key, and naming the trade-offs out loud.

  • Database sharding system design interview
  • Database sharding interview explanation