Illustration Image

Keeping Data In Denormalized NoSql Databases (Cassandra/ScyllaDb) Tables In Sync?

I am new to NoSql databases like Cassandra/ScyllaDb and trying to wrap my head around NoSql database tables design and how to keep duplicated data in multiple tables in sync. I just read this post about NoSql Data Modeling and here are the important screenshots from the post.

Application workflow

enter image description here

Chebotko Diagram

enter image description here

I have some few questions regarding the tables design and keeping duplicated data in multiple tables in sync.

  1. There are tables for users and videos. Why isn't any table for comments since it is also an entity.

  2. If a user is adding a comment to a video there has to be two inserts statements I think. One insert for the comments_by_user table and another insert for the comments_by_video table and the commentId value must be the same for the two tables. How do you make sure the commentId in the two tables is the same? Do you for instance assign the timeuuid to a variable and then use the variable in the commentId slot for the two insert statements?

    Example:

    var myuuid = timeuuid();
    
    insert into comments_by_user(...)values(..., myuuid); 
    
    insert into comments_by_video(...) values(...,myuuid);   
    

    The reason am asking this is if a user uses for instance a timeuuid() function in both insert statements then the timeuuid will not be the same for the commentid in both tables because timeuuid() will generate different values.

  3. Should in case there should be a comments table then if a user wants to add comments then there should be three inserts statements. The first insert statement to the comments table and the the comment id that is returned will be used to insert into comments_by_user and comments_by_video.

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. Sponsored by Anant Corporation and Datastax, and Developed by Anant Corporation.

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?