Database / Apache Cassandra Intermediate and Advanced interview questions
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....
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...
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....
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,...
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]...
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...
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...
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....
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....
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...
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....
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....
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.
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....
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....
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 ....
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...
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....
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....
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...
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)....
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.
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...
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....
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 (...
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...
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...
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...
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...
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....
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
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...
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...
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...
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....
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....
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....
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....
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 =...
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...
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...
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....
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 ,...
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...
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....