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
Chebotko Diagram
I have some few questions regarding the tables design and keeping duplicated data in multiple tables in sync.
There are tables for users and videos. Why isn't any table for comments since it is also an entity.
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 thecomments_by_video
table and thecommentId
value must be the same for the two tables. How do you make sure thecommentId
in the two tables is the same? Do you for instance assign thetimeuuid
to a variable and then use the variable in thecommentId
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.
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 thecomments
table and the thecomment id
that is returned will be used to insert intocomments_by_user
andcomments_by_video
.