Book Image

Learning Apache Cassandra

By : Matthew Brown
4 (1)
Book Image

Learning Apache Cassandra

4 (1)
By: Matthew Brown

Overview of this book

Table of Contents (19 chapters)
Learning Apache Cassandra
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The problem with concurrent updates


Let's add a new feature to our My Status application: the users' ability to "star" their friends' status updates to indicate their approval. For each status update, we'll store a list of the users who have starred that status update so that we can display the usernames to the author of the update.

Serializing the collection

One approach is to simply store the list of users in a text column in some serialized form. JSON is a versatile serialization format for such scenarios, so we'll use it. First, we'll add the column to the user_status_updates table, recalling the technique from Adding columns to tables section in Chapter 7, Expanding Your Data Model:

ALTER TABLE "user_status_updates"
ADD "starred_by_users" text;

Simple enough. Now let's suppose that bob wants to star one of the status updates of alice. From the application's standpoint, this means appending bob to the list of users who have starred alice's update. First, we'll read the existing list:

SELECT...