Lightweight transactions in Cassandra
Cassandra support for transactions Unlike commonly used relational database platforms, Cassandra does not support ACID transactions. Cassandra prioritizes availability and being partition-tolerant above consistency. Consistency is tuneable, but in general, the design precludes transactions. That is, there is no guarantee, even when configuring a high level of consistency, that a read will remain accurate by the time a related write happens. Cassandra does support what are called lightweight transactions (LWTs), and these are sometimes used in applications to approximate ACID transactions. This feature uses an extension of the Paxos algorithm. The Paxos algorithm The Paxos algorithm relies on distributed nodes coming to a consensus. Very basically, a node that wants to accept a write communicates with other nodes to get a "promise" from them that no other writes will be accepted until this one is complete. Cassandra extends this algorithm with LWTs to include two additional steps, so that there are four round-trip network communications in total:
- prepare/promise: The node wishing to accept a write communicates with other nodes, and the other nodes respond with an agreement.
- read/results: The initiating node makes a read request, and the other nodes respond with the data.
- propose/accept: The initiating node sends the proposed write, and the other nodes accept it.
- commit/ack: The initiating node commits the write, and the other nodes acknowledge (and commit) the write.