CASSANDRA Skills 5 — Questions and Answers
Question 1: Which Cassandra feature lets you define a secondary sort order within a partition using the PRIMARY KEY definition?
- Partition index
- Clustering columns (Correct answer)
- Secondary index
- Static columns
Correct answer: Clustering columns
Clustering columns are the non-partition components of the primary key and determine the sort order of rows within a partition.
Question 2: You need to read the most recent 10 events for a user from a time-ordered table. Which CQL clause should you use?
- FETCH FIRST 10 ROWS ONLY
- LIMIT 10 (Correct answer)
- TOP 10
- ROWNUM <= 10
Correct answer: LIMIT 10
The LIMIT clause in CQL restricts the number of rows returned per partition, making it efficient for paginated or top-N queries.
Question 3: What is a 'token-aware' load balancing policy in a Cassandra driver, and why is it preferred?
- It routes requests to the node that owns the relevant partition, reducing hops (Correct answer)
- It balances load by always sending writes to the node with the fewest open connections
- It distributes requests round-robin among all nodes regardless of token ownership
- It forces reads through the coordinator to ensure consistency level compliance
Correct answer: It routes requests to the node that owns the relevant partition, reducing hops
Token-aware routing sends queries directly to the replica that owns the data, avoiding an extra coordinator hop and reducing latency.
Question 4: What is the purpose of the `static` column type in a Cassandra table?
- A column whose value cannot be changed after insertion
- A column that stores one value per partition shared across all rows in that partition (Correct answer)
- A column that is indexed automatically for fast lookups
- A column that bypasses the memtable and writes directly to SSTables
Correct answer: A column that stores one value per partition shared across all rows in that partition
Static columns hold a single value per partition key, useful for storing per-partition metadata without duplicating it in every clustering row.
Question 5: Which of the following best describes the role of the snitch in Apache Cassandra?
- Detects and removes corrupt SSTables from the data directory
- Informs Cassandra about network topology so replicas are placed in different racks or datacenters (Correct answer)
- Monitors gossip traffic and removes nodes that fail to heartbeat
- Coordinates lightweight transactions by acting as the Paxos proposer
Correct answer: Informs Cassandra about network topology so replicas are placed in different racks or datacenters
The snitch tells Cassandra about the relative network proximity of nodes, enabling intelligent replica placement across racks and datacenters.
Question 6: What is the risk of using BATCH statements in Cassandra for writes across multiple partitions?
- Batches are not supported in CQL for multi-partition writes
- Multi-partition batches create a hot spot on the coordinator and do not provide atomicity guarantees (Correct answer)
- Batches bypass the commit log, risking data loss on coordinator failure
- Multi-partition batches are serialized through Paxos, which is extremely slow
Correct answer: Multi-partition batches create a hot spot on the coordinator and do not provide atomicity guarantees
Multi-partition batches serialize through the coordinator node, creating a bottleneck, and unlike single-partition batches, they do not guarantee atomicity.
Question 7: How can you monitor the number of pending compaction tasks on a Cassandra node in real time?
- SELECT * FROM system.compactions
- nodetool compactionstats (Correct answer)
- nodetool cfstats | grep pending
- cqlsh -e 'SHOW COMPACTIONS'
Correct answer: nodetool compactionstats
`nodetool compactionstats` displays currently running and pending compaction tasks along with their progress and estimated completion.
Which Cassandra feature lets you define a secondary sort order within a partition using the PRIMARY KEY definition?