This document discusses strategies for updating data in Apache Cassandra beyond using read-modify-write operations. It describes how eventual consistency allows safe updates without locking by propagating changes asynchronously. It also covers Cassandra features like collections, lightweight transactions, and content-addressable storage that provide flexible data models for modern web-scale applications while avoiding the need for read-modify-write in many cases.
28. In Practice
• In practice, RMW is sometimes unavoidable
• Recent versions of Cassandra support RMW
• Use them only when necessary
• Or when performance hit is mitigated elsewhere or irrelevant
29. Cassandra Collections
CREATE TABLE posts (
id uuid,
body varchar,
created timestamp,
authors set<varchar>,
tags set<varchar>,
PRIMARY KEY(id)
);
!
INSERT INTO posts (id,body,created,authors,tags) VALUES (
ea4aba7d-9344-4d08-8ca5-873aa1214068,
‘アルトビーの犬はばかね’,
‘now',
[‘アルトビー’, ’ィオートビー’],
[‘dog’, ‘silly’, ’犬’, ‘ばか’]
);
30. Cassandra Collections
CREATE TABLE metrics (
bucket timestamp,
time timestamp,
value blob,
labels map<varchar,varchar>,
PRIMARY KEY(bucket)
);
31. Lightweight Transactions
• Cassandra 2.0 and on support LWT based on PAXOS
• PAXOS is a distributed consensus protocol
• Given a constraint, Cassandra ensures correct ordering
32. Lightweight Transactions
UPDATE
users
SET
username=‘tobert’
WHERE
id=68021e8a-‐9eb0-‐436c-‐8cdd-‐aac629788383
IF
username=‘renice’;
!
INSERT
INTO
users
(id,
username)
VALUES
(68021e8a-‐9eb0-‐436c-‐8cdd-‐aac629788383,
‘renice’)
IF
NOT
EXISTS;
!
!
33. Conclusion
• Businesses are scaling further and faster than ever
• Assume you have to provide utility-grade service
• Data models and application architectures need to change to keep up
• Avoiding Read/Modify/Write makes high-performance easier
• Cassandra provides tools for safe RMW when you need it
!
• Questions?