Illustration Image

7/1/2022

Reading time:4

Apache Cassandra Lunch #80: Using Cassandra for a Content Management System - Business Platform Team

logo

This resource is based on an article originally published here.

In Cassandra Lunch #80, we discussed how DataStax Astra can be used to create and track a content management system. We will demo a small application that is a clone of Tik Tok using Astra’s Document API. The live recording of Cassandra Lunch, which includes a more in-depth discussion and a demo, is embedded below in case you were not able to attend live. If you would like to attend Apache Cassandra Lunch live, it is hosted every Wednesday at 12 PM EST. Register here now!

Any discussion involving Cassandra needs to start with the data model. NoSQL systems provide fast read and write operations because tables tend to be created specifically to query certain data. Unlike traditional SQL schemas, joins are not allowed. This requires thinking about the data that is going to be stored and retrieved before creating a table. Special consideration needs to be given for what your Primary, Partition, and Clustering keys. The primary/partition key determines what columns a table can be queried. The clustering key determines how that data can be sorted.

The following Chebotko diagram demonstrates a Cassandra data model for a video application. Primary keys are denoted with a “K” and clustering columns are indicated with a “C” and an arrow up or down.

Using Cassandra for a Content Management System Chetbotko Diagram
Image from: https://scotch.io/tutorials/five-steps-to-an-awesome-data-model-in-apache-cassandra

DataStax Astra

For the demonstration in Cassandra Lunch #80: Using Cassandra for a Content Management System, we used DataStax Astra. Astra is a Cassandra-as-a-Service in the cloud. Some great things to point out about Astra are that it is free to start, database and infrastructure administration are optional, and there are multiple options to choose from when connecting to Cassandra via API.

  • Document API: schemaless storage of JSON documents
  • Stargate REST API: perform CRUD operations on data using a cross-language interface.
  • Stargate GraphQL API: query and mutate tables in your keyspace.
  • Stargate gRPC API: create CQL queries in Rust, Go, Node.js, or Java.

Stargate Document API

In our demonstration, we used Astra’s Stargate Document API. As mentioned above, this allows us to query and modify data stored as unstructured JSON documents in a collection and does not require the aforementioned data modeling typical of Cassandra. Once a namespace is created we can start adding data by connecting to the API via a URL containing the database id, region, keyspace name, and an authorization token (a Cassandra token) in the authorization header.

https://<ASTRA_DB_ID>-<ASTRA_DB_REGION>-apps.astra.datastax.com/api/rest/v2/namespaces/<ASTRA_DB_KEYSPACE>/collections/<ASTRA_DB_TABLE>

Multiple collections can be stored in a namespace, but a collection can only be stored in a single namespace. Collections are specified once a document is inserted. Once a document is inserted, each value in the JSON object is stored as a cell in the table. Below is an image of how a table is created when a document is submitted to Stargate’s Document API.

Using Cassandra for a Content Management System: image of how a table is created when a JSON object is submitted to Stargate's Document API
Image from: https://stargate.io/2020/10/19/the-stargate-cassandra-documents-api.html

One thing to note is that writes are a batch and will contain inserts and deletes. This can cause document rows to show two different states for a JSON field. If this happens, the document API will resolve by accepting the data with the later write time. To learn more about the Stargate Document API and details surrounding how deletes are handled and API performance checkout Stargate’s blog post.

To follow along in leveraging this information in order to create a Tik Tok clone be sure to check out the video and repository linked below. If you missed Cassandra Lunch #78: Cass Operator, it is embedded below! Additionally, all of our live events can be rewatched on our YouTube channel, so be sure to subscribe and turn on your notifications!

Resources:

Cassandra.Link

Cassandra.Link is a knowledge base that we created for all things Apache Cassandra. Our goal with Cassandra.Link was to not only fill the gap of Planet Cassandra but to bring the Cassandra community together. Feel free to reach out if you wish to collaborate with us on this project in any capacity.

We are a technology company that specializes in building business platforms. If you have any questions about the tools discussed in this post or about any of our services, feel free to send us an email!

Related Articles

Placeholder
graph.visualization
datatax
astra

Explore Further

cassandra

datastax.astra

stargate.document.api

Become part of our
growing community!
Welcome to Planet Cassandra, a community for Apache Cassandra®! We're a passionate and dedicated group of users, developers, and enthusiasts who are working together to make Cassandra the best it can be. Whether you're just getting started with Cassandra or you're an experienced user, there's a place for you in our community.
A dinosaur
Planet Cassandra is a service for the Apache Cassandra® user community to share with each other. From tutorials and guides, to discussions and updates, we're here to help you get the most out of Cassandra. Connect with us and become part of our growing community today.
© 2009-2023 The Apache Software Foundation under the terms of the Apache License 2.0. Apache, the Apache feather logo, Apache Cassandra, Cassandra, and the Cassandra logo, are either registered trademarks or trademarks of The Apache Software Foundation.

Get Involved with Planet Cassandra!

We believe that the power of the Planet Cassandra community lies in the contributions of its members. Do you have content, articles, videos, or use cases you want to share with the world?