Skip to content

Instantly share code, notes, and snippets.

@Nathan-Nesbitt
Last active April 5, 2020 19:07
Show Gist options
  • Save Nathan-Nesbitt/6518c61e173d7e1e30c52818cf22c9d5 to your computer and use it in GitHub Desktop.
Save Nathan-Nesbitt/6518c61e173d7e1e30c52818cf22c9d5 to your computer and use it in GitHub Desktop.

Working with Cassandra

Handling multiple tables

Since Cassandra is NoSQL we cannot assume consistancy accross tables (we may have the same value in n tables). Therefore, we need to use batch statements which are precreated queries that run accross multiple tables. An example of a batch statement is:

BEGIN BATCH
  INSERT INTO userpage_posts (username, datestamp) VALUES ('user1', '2020-01-01');
  INSERT INTO subscribed_feed (username, datestamp) VALUES ('user1', '2020-01-01');
APPLY BATCH;

We can use this to ensure all insertions, updates, and deletes are applied consistantly accross all tables. This has a cost for insertion, but as Cassandra provides decreased insertion time costs we don't need to worry about this now.

To read more about BATCH you can read the DataStax Documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment