CASSANDRA Skills 4 — Questions and Answers
Question 1: A developer wants to add a new column to an existing Cassandra table without downtime. Which CQL statement should they use?
- MODIFY TABLE orders ADD shipped_date timestamp
- ALTER TABLE orders ADD shipped_date timestamp (Correct answer)
- UPDATE TABLE orders COLUMN shipped_date timestamp
- CREATE COLUMN shipped_date timestamp ON orders
Correct answer: ALTER TABLE orders ADD shipped_date timestamp
ALTER TABLE ... ADD is the correct CQL syntax for adding a new column to an existing table, and it is a schema-only change with no data rewrite.
Question 2: What is a Cassandra lightweight transaction (LWT) and when would you use it?
- A read-only transaction that bypasses the commit log for speed
- A compare-and-set operation that uses Paxos to guarantee conditional writes (Correct answer)
- A batch write that spans multiple partitions atomically
- A transaction that only commits if the coordinator node is the leader
Correct answer: A compare-and-set operation that uses Paxos to guarantee conditional writes
LWTs use the Paxos consensus protocol to implement conditional INSERT/UPDATE/DELETE operations (e.g., INSERT IF NOT EXISTS), at the cost of higher latency.
Question 3: How does the virtual node (vnode) feature improve cluster operations compared to single-token assignment?
- Vnodes reduce the number of SSTables per node
- Vnodes make data distribution more even and simplify adding or removing nodes (Correct answer)
- Vnodes allow a single node to act as both coordinator and replica
- Vnodes compress partition keys to reduce network traffic
Correct answer: Vnodes make data distribution more even and simplify adding or removing nodes
With vnodes, each physical node owns many small token ranges, so bootstrapping and decommissioning redistributes data in smaller, parallel streams.
Question 4: Which read consistency level provides the lowest latency but weakest consistency guarantee in Cassandra?
- QUORUM
- LOCAL_QUORUM
- ONE (Correct answer)
- ALL
Correct answer: ONE
Consistency level ONE returns the response from the first replica that responds, offering the fastest reads but risking stale data.
Question 5: What is the effect of setting a very low `memtable_flush_writers` value in a write-heavy Cassandra workload?
- SSTables will be merged more aggressively during compaction
- Memtable flushes will become a bottleneck, increasing write latency (Correct answer)
- Read throughput will decrease due to fewer bloom filter checks
- GC pressure will drop because fewer objects are promoted to old-gen heap
Correct answer: Memtable flushes will become a bottleneck, increasing write latency
Too few flush writers means memtables queue up waiting to be flushed to disk, which eventually backs up the write path and increases latency.
Question 6: A Cassandra table uses a composite primary key of (user_id, event_time). Which query will execute efficiently without ALLOW FILTERING?
- SELECT * FROM events WHERE event_time > '2024-01-01'
- SELECT * FROM events WHERE user_id = 'abc123' (Correct answer)
- SELECT * FROM events WHERE event_time = '2024-06-15' AND user_id = 'abc123'
- SELECT * FROM events WHERE user_id IN ('abc', 'def') AND event_time < '2024-01-01'
Correct answer: SELECT * FROM events WHERE user_id = 'abc123'
Providing the full partition key (user_id) allows Cassandra to route the query directly to the correct partition without a cluster-wide scan.
Question 7: What does the `cassandra-stress` tool primarily help you accomplish?
- Validating CQL syntax before running queries in production
- Load testing and benchmarking a Cassandra cluster under configurable workloads (Correct answer)
- Monitoring real-time CPU and memory usage across all nodes
- Automatically tuning compaction thresholds based on disk I/O patterns
Correct answer: Load testing and benchmarking a Cassandra cluster under configurable workloads
`cassandra-stress` is a load-generation tool bundled with Cassandra that simulates read/write workloads to measure throughput and latency.
A developer wants to add a new column to an existing Cassandra table without downtime.
Which CQL statement should they use?