Prev Next

Database / Apache Cassandra Intermediate and Advanced interview questions

1. What is the difference between a partition key and a clustering key? 2. How does Cassandra achieve tunable consistency? 3. What is the difference between consistency levels ONE, QUORUM, and ALL? 4. Explain the write path in Cassandra? 5. Explain the read path in Cassandra? 6. What is the role of a coordinator node in Cassandra? 7. What is the gossip protocol in Cassandra? 8. How does Cassandra detect node failure? 9. What are virtual nodes (vnodes) and why does Cassandra use them? 10. What is consistent hashing and how does Cassandra use it? 11. What is a partitioner in Cassandra? 12. What is a snitch in Cassandra and what does it do? 13. What is the difference between SimpleStrategy and NetworkTopologyStrategy? 14. What is hinted handoff in Cassandra? 15. What is read repair in Cassandra? 16. What is the difference between hinted handoff and read repair? 17. What is anti-entropy repair and why is it needed? 18. What is the difference between full repair and incremental repair? 19. What are tombstones in Cassandra? 20. Why can excessive tombstones degrade Cassandra performance? 21. What is gc_grace_seconds and why does it matter? 22. What are the different compaction strategies available in Cassandra? 23. When would you choose Leveled Compaction Strategy over Size-Tiered Compaction Strategy? 24. What is Time Window Compaction Strategy used for? 25. What are lightweight transactions (LWT) in Cassandra? 26. Why are lightweight transactions expensive in Cassandra? 27. What role does the Paxos protocol play in Cassandra's lightweight transactions? 28. What are secondary indexes in Cassandra, and when should you avoid them? 29. What is a materialized view in Cassandra? 30. What is the difference between a secondary index and a materialized view? 31. What is SASI (SSTable Attached Secondary Index) in Cassandra? 32. What are User Defined Types (UDTs) in Cassandra? 33. What are counter columns in Cassandra and what are their limitations? 34. What is a wide partition in Cassandra and why is it a problem? 35. How do you model time-series data in Cassandra? 36. What is the ALLOW FILTERING clause and why is it risky? 37. What is a batch statement in Cassandra, and what's the difference between logged and unlogged batches? 38. Why shouldn't Cassandra batches be used to improve write throughput? 39. What is Change Data Capture (CDC) in Cassandra? 40. What is speculative retry in Cassandra? 41. What is token awareness in Cassandra drivers? 42. What is the role of Merkle trees in Cassandra's repair process? 43. How do you add a new node to a Cassandra cluster? 44. What is nodetool cleanup used for? 45. How do you handle consistency across multiple datacenters in Cassandra?

1. What is the difference between a partition key and a clustering key?

The partition key decides which node (and its replicas) a row physically lives on. Cassandra hashes the partition key with the configured partitioner to get a token, and that token maps to a position on the ring. Every row sharing the same partition key value lands on the same set of replicas. Th...

Read full answer

2. How does Cassandra achieve tunable consistency?

Cassandra lets you pick a consistency level (CL) independently for every read and every write, instead of hard-coding one global guarantee. The CL just says how many replicas out of the replication factor (N) must acknowledge before the coordinator replies to the client. Writes go to all N replic...

Read full answer

3. What is the difference between consistency levels ONE, QUORUM, and ALL?

These are three of the most commonly used consistency levels, and each shifts the balance between speed, availability, and correctness differently. ONE QUORUM ALL Only 1 replica must respond. (N/2)+1 replicas must respond. All N replicas must respond. Fastest, most available. Balances speed and c...

Read full answer

4. Explain the write path in Cassandra?

A write in Cassandra is optimized to be fast and durable without doing any disk seeks or read-before-write checks. flowchart LR A[Client sends write] --> B[Coordinator node] B --> C[Commit Log - append only, durability] B --> D[Memtable - in-memory, per table] D -->|threshold reached| E[Flush to ...

Read full answer

5. Explain the read path in Cassandra?

Reads are more involved than writes because data for one partition can be spread across the memtable and several SSTables. flowchart LR A[Client read request] --> B[Coordinator node] B --> C1[Replica 1] B --> C2[Replica 2 - if CL requires] C1 --> D[Check Memtable] C1 --> E[Bloom Filter per SSTabl...

Read full answer

6. What is the role of a coordinator node in Cassandra?

Any node in a Cassandra cluster can act as a coordinator for a given client request — there is no dedicated coordinator node or single point of entry, unlike a master node in other systems. It receives the client's query and identifies, using the token ring and the partitioner, which nodes ...

Read full answer

7. What is the gossip protocol in Cassandra?

Gossip is the peer-to-peer protocol Cassandra uses to let nodes discover and track the state of every other node without any central coordinator. Every second, each node picks one to three other nodes at random and exchanges state information with them. The state includes things like heartbeat ve...

Read full answer

8. How does Cassandra detect node failure?

Cassandra uses a Phi Accrual Failure Detector rather than a simple fixed heartbeat timeout to decide whether a node is up or down. Each node tracks the history of arrival times of heartbeats (via gossip) from every other node. From that history it builds a statistical distribution of expected int...

Read full answer

9. What are virtual nodes (vnodes) and why does Cassandra use them?

Before vnodes, each physical node owned exactly one large, contiguous token range on the ring. That made rebalancing painful: adding or removing a node meant recalculating and manually moving huge chunks of token ranges. Virtual nodes (vnodes) let each physical machine own many small, randomly di...

Read full answer

10. What is consistent hashing and how does Cassandra use it?

Consistent hashing is the technique that lets Cassandra distribute data across nodes so that adding or removing a node only reshuffles a small fraction of the data, instead of the entire dataset. Cassandra arranges a hash space (from 0 to a maximum value) into a logical ring . Each node is assign...

Read full answer

11. What is a partitioner in Cassandra?

The partitioner is the component that converts a partition key into a numeric token , which is what actually determines where data sits on the ring. Murmur3Partitioner is the default and recommended partitioner in modern Cassandra. It hashes the partition key using the fast, non-cryptographic Mur...

Read full answer

12. What is a snitch in Cassandra and what does it do?

A snitch tells Cassandra about the network topology — which datacenter and rack each node belongs to. This information drives two critical decisions: where to place replicas, and which replica a coordinator should prefer to talk to. GossipingPropertyFileSnitch : the most common production c...

Read full answer

13. What is the difference between SimpleStrategy and NetworkTopologyStrategy?

These are Cassandra's two main replication strategies , and they answer the same question — "where should replicas go?" — very differently. SimpleStrategy NetworkTopologyStrategy Places replicas on the next nodes clockwise on the ring, ignoring topology. Places replicas per-datacenter...

Read full answer

14. What is hinted handoff in Cassandra?

Hinted handoff is Cassandra's way of tolerating a temporarily unavailable replica without failing the write or immediately falling out of sync. The coordinator sends the write to all replicas as usual. If a replica is down or unreachable, the coordinator (or another live node) stores a hint ̵...

Read full answer

15. What is read repair in Cassandra?

Read repair fixes inconsistent replicas as a side effect of normal read traffic, rather than waiting for a scheduled repair job. When a coordinator queries multiple replicas to satisfy the consistency level, it compares the responses. If the replicas disagree, the coordinator identifies the most ...

Read full answer

16. What is the difference between hinted handoff and read repair?

Both mechanisms help replicas converge, but they trigger under different circumstances and fix different kinds of inconsistency. Hinted Handoff Read Repair Triggered when a replica is unreachable during a write . Triggered when replicas disagree during a read . Coordinator stores a hint and repla...

Read full answer

17. What is anti-entropy repair and why is it needed?

Anti-entropy repair (run via nodetool repair ) is the mechanism that guarantees replicas eventually converge, covering the gaps that hinted handoff and read repair leave behind. Each replica builds a Merkle tree — a hash tree summarizing the data in a token range. Replicas exchange and comp...

Read full answer

18. What is the difference between full repair and incremental repair?

Both are forms of anti-entropy repair, but they differ in how much data gets re-validated each time nodetool repair runs. Full Repair Incremental Repair Recomputes Merkle trees over all SSTables every run. Only compares SSTables not already marked repaired . Slower and more I/O intensive as data ...

Read full answer

19. What are tombstones in Cassandra?

Because Cassandra's SSTables are immutable once written, it cannot simply erase a row or column in place. Instead, a delete writes a tombstone — a special marker recording that a value was deleted, along with a timestamp. Tombstones can exist at the cell, row, range, or partition level, dep...

Read full answer

20. Why can excessive tombstones degrade Cassandra performance?

A tombstone is not free — it still takes up space and, more importantly, the read path has to scan past it to figure out that a value was deleted. A read touching a partition with thousands of tombstones must iterate over all of them in memory before it can return the small number of live r...

Read full answer

21. What is gc_grace_seconds and why does it matter?

gc_grace_seconds is a per-table setting that defines how long a tombstone must be kept before it becomes eligible for permanent removal during compaction. It defaults to 864000 seconds (10 days). The window exists to give every replica a chance to receive the delete, whether through the original ...

Read full answer

22. What are the different compaction strategies available in Cassandra?

Compaction merges multiple SSTables into fewer, larger ones, discarding overwritten data and expired tombstones along the way. Cassandra offers a few strategies, each tuned for a different workload shape. STCS LCS TWCS Size-Tiered: merges similarly-sized SSTables together. Leveled: organizes SSTa...

Read full answer

23. When would you choose Leveled Compaction Strategy over Size-Tiered Compaction Strategy?

The choice comes down to whether your workload is more sensitive to read latency or to compaction overhead. Choose LCS when reads dominate and you need predictable, low-latency lookups — LCS guarantees a row exists in at most one SSTable per level (aside from level 0), so a read touches far...

Read full answer

24. What is Time Window Compaction Strategy used for?

Time Window Compaction Strategy (TWCS) is purpose-built for time-series or append-mostly data where rows naturally expire together, such as metrics, logs, or IoT sensor readings written with a TTL. SSTables are grouped into fixed-size time windows (e.g. one window per day), and compaction only me...

Read full answer

25. What are lightweight transactions (LWT) in Cassandra?

Lightweight transactions give Cassandra a way to do compare-and-set style operations — "only apply this write if a condition holds" — which normal writes cannot express, since ordinary writes are unconditional and last-write-wins. INSERT INTO users (user_id, email) VALUES ( 'u1' , 'a@...

Read full answer

26. Why are lightweight transactions expensive in Cassandra?

Regular Cassandra writes are cheap precisely because they skip coordination: the coordinator just fires the mutation at all replicas and waits for the consistency-level count of acknowledgements. LWTs cannot take that shortcut, because they must guarantee only one outcome is agreed on across repl...

Read full answer

27. What role does the Paxos protocol play in Cassandra's lightweight transactions?

Cassandra implements a variant of the Paxos consensus algorithm to make LWTs linearizable across replicas without needing a single elected leader. Prepare/Promise : the coordinator asks replicas to promise not to accept any older proposal, establishing a ballot number higher than anything seen be...

Read full answer

28. What are secondary indexes in Cassandra, and when should you avoid them?

A secondary index lets you query on a non-partition-key column without specifying the partition key, something Cassandra normally forbids for efficiency reasons. CREATE INDEX ON orders (status); SELECT * FROM orders WHERE status = 'pending' ; Under the hood, each node only indexes the data it loc...

Read full answer

29. What is a materialized view in Cassandra?

A materialized view (MV) is a server-managed table that Cassandra automatically keeps in sync with a base table, letting you query the same data with a different partition/clustering key layout without hand-writing your own denormalization logic. CREATE MATERIALIZED VIEW orders_by_status AS SELEC...

Read full answer

30. What is the difference between a secondary index and a materialized view?

Both let you query on something other than the base table's partition key, but they solve the problem in very different ways. Secondary Index Materialized View Indexes an existing column in place on the base table. Creates a separate physical table with its own partition key. Query still fans out...

Read full answer

31. What is SASI (SSTable Attached Secondary Index) in Cassandra?

SASI is an alternative secondary index implementation that supports query patterns the built-in 2i index cannot, most notably prefix/substring text matching and range queries on non-partition-key columns. CREATE CUSTOM INDEX ON articles (title) USING 'org.apache.cassandra.index.sasi.SASIIndex' WI...

Read full answer

32. What are User Defined Types (UDTs) in Cassandra?

User Defined Types let you group related fields into a single named, reusable structure, similar to a struct, instead of flattening everything into individual table columns. CREATE TYPE address ( street text, city text, zip text ); CREATE TABLE customers ( customer_id uuid PRIMARY KEY , name text...

Read full answer

33. What are counter columns in Cassandra and what are their limitations?

Counter columns are a special column type designed for distributed, atomic increment/decrement operations, such as tracking view counts or like counts, where many clients may update the same value concurrently. CREATE TABLE page_views ( page_id text PRIMARY KEY , views counter ); UPDATE page_view...

Read full answer

34. What is a wide partition in Cassandra and why is it a problem?

A wide partition is a partition that has grown far larger than a healthy size — typically flagged once it approaches the hundreds-of-megabytes range or accumulates millions of cells, though the practical threshold depends on hardware and access patterns. Wide partitions usually come from a ...

Read full answer

35. How do you model time-series data in Cassandra?

Good time-series modeling in Cassandra centers on two goals: keep partitions bounded in size, and keep the most commonly queried time range fast to retrieve. CREATE TABLE sensor_readings ( sensor_id text, day text, -- bucket, e.g. '2026-07-21' reading_time timestamp , value double, PRIMARY KEY ((...

Read full answer

36. What is the ALLOW FILTERING clause and why is it risky?

Cassandra normally rejects queries that would require scanning data across partitions inefficiently — for example, filtering on a non-indexed, non-key column. ALLOW FILTERING overrides that safety check and lets the query run anyway. SELECT * FROM orders WHERE amount > 1000 ALLOW FILTERING;...

Read full answer

37. What is a batch statement in Cassandra, and what's the difference between logged and unlogged batches?

A batch statement groups multiple CQL writes into a single request. Its main purpose is atomicity across statements, not performance. Logged Batch Unlogged Batch Default batch type; writes a batchlog entry first for atomicity. Skips the batchlog; no atomicity guarantee across partitions. Guarante...

Read full answer

38. Why shouldn't Cassandra batches be used to improve write throughput?

It's a common misconception carried over from relational databases that batching writes always improves throughput. In Cassandra, batching across multiple partitions usually does the opposite. A multi-partition logged batch has to write to the batchlog first, then fan out each individual statemen...

Read full answer

39. What is Change Data Capture (CDC) in Cassandra?

Change Data Capture lets external systems consume a stream of the mutations written to a Cassandra table, without polling the table itself — useful for feeding data pipelines, search indexes, caches, or event-driven architectures. ALTER TABLE orders WITH cdc = true ; Once enabled on a table...

Read full answer

40. What is speculative retry in Cassandra?

Speculative retry is a per-table setting that helps tame tail latency by not letting the coordinator wait indefinitely on the single slowest replica. When the coordinator sends a read to the replicas needed for the consistency level, one of them may occasionally respond slowly due to GC pauses, c...

Read full answer

41. What is token awareness in Cassandra drivers?

Token awareness is a driver-side optimization where the client library computes, on its own, which node actually owns a given partition — before sending the request — instead of connecting to an arbitrary node and letting it coordinate. The driver maintains a local copy of the cluster...

Read full answer

42. What is the role of Merkle trees in Cassandra's repair process?

Comparing every row between two replicas byte-by-byte to find differences would be prohibitively slow at scale. Merkle trees let Cassandra compare huge token ranges efficiently by comparing hashes instead of raw data. For a given token range, a replica divides the data into smaller sub-ranges and...

Read full answer

43. How do you add a new node to a Cassandra cluster?

Adding a node is designed to be an online operation — the rest of the cluster keeps serving traffic while the new node joins and streams data. Install Cassandra on the new host and configure cassandra.yaml : same cluster_name , correct seeds list (pointing at existing nodes, not itself), co...

Read full answer

44. What is nodetool cleanup used for?

nodetool cleanup removes data that a node is no longer responsible for, reclaiming disk space after the cluster's token ownership has changed. When a new node joins (or an existing node's token ranges otherwise shift), other nodes may keep serving reads/writes correctly for a while, but they stil...

Read full answer

45. How do you handle consistency across multiple datacenters in Cassandra?

Multi-datacenter Cassandra deployments need consistency levels that are aware of DC boundaries, since waiting on remote datacenters for every request can add significant latency. LOCAL_QUORUM EACH_QUORUM Requires a quorum of replicas within the local DC only. Requires a quorum of replicas in ever...

Read full answer

«
»

Comments & Discussions