Database / Apache Cassandra Intermediate and Advanced interview questions
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. |
| Guarantees all statements eventually apply, even after a coordinator crash mid-batch. | Faster, but a crash mid-batch can leave some writes applied and others not. |
| Adds overhead: extra writes to the batchlog system table. | Best suited for statements that all target the same partition, where atomicity is naturally scoped anyway. |
BEGIN UNLOGGED BATCH INSERT INTO orders (order_id, status) VALUES ('o1', 'new'); INSERT INTO orders (order_id, status) VALUES ('o2', 'new'); APPLY BATCH;
Logged batches are appropriate when you genuinely need cross-partition atomicity (e.g. updating a record and a corresponding denormalized table together), while unlogged batches are best reserved for multiple writes to the same partition, where they can reduce round trips without sacrificing correctness.
More Related questions...