cassandradatastaxcassandra-2.2

Cassandra batch isolation guarantee


I have a question regarding Cassandra batch isolation:

Our cluster consist of a single datacenter, replication factor of 3, reading and writing in LOCAL_QUORUM. We must provide a news feed resembling an 'after' trigger, to notify clients about CRUD events of data in the DB. We thought of performing the actual operation, and inserting an event on another table (also in another partition), within a batch. Asynchronously, some process would read events from event table and send them through an MQ.

Because we're writing to different partitions, and operation order is not necessarily maintained in a batch operation; is there a chance our event is written, and our process read it before our actual data is persisted?

Could the same happen in case our batch at last fails?

Regards, Alejandro


Solution

  • From ACID properties, Cassandra can provide ACD. Therefore, don't expect Isolation in its classical sense.

    Batching records will provide you with Atomicity. So it does guarantee that all or none of the records within a batch are written. However, because it doesn't guarantee Isolation, you can end up having some of the records persisted and others not (e.g. wrote to your queue table, but not master table).

    Cassandra docs explain how it works:

    To achieve atomicity, Cassandra first writes the serialized batch to the batchlog system table that consumes the serialized batch as blob data. When the rows in the batch have been successfully written and persisted (or hinted) the batchlog data is removed. There is a performance penalty for atomicity.

    Finally, using Cassandra table as MQ is considered anti-pattern.