1
votes

In this article the author illustrates several options for modeling many-to-many relationship in Cassandra. I would like to get some more clarifications on two of them:

  1. Why option 4 would take more space? It seems like you are just "appending" Item_by_user to User column space.
  2. Also, in option 4, how can you define composite columns as the author suggests? It seems like you have two groups of columns: 1) Name, Email and 2) Likes whereas the latter is wide(?). What would be the CQL code that defines Name, Email and wide columns for Likes for the User table?

Thanks.

The following images are taken form the article mentioned above:

enter image description here

enter image description here

2

2 Answers

2
votes

As far as first question goes it looks to me that it will take same amount of space only one row per user and per item less because you keep everything in single row.

As for second question you can take a look at static columns (here is cql documentation). Basically it is a way to define column which will be shared by all values in one row (user details in user table and item details in items table) and you can update value only by using partitioning key.

Second solution can be to model which items user liked as map type (here is map documentation) and same thing goes to items (create a map of users which liked that item).

0
votes

I suggest you to get more information about Data modeling in Cassandra. I've read A Big Data Modeling Methodology for Apache Cassandra and Basic Rules of Cassandra Data Modeling as useful articles in this case. They will help you understanding about modelling the tables based on your queries (Query-Driven methodology) and data duplication and its advantages/disadvantages.