'Cassandra comments example model best practice
I really want competent specialists to point me in the right direction, due to the lack of serious experience in designing models. So have some questions that i can't find answers to. With your permission, I will first give an example first.
Imagine, that we have some table named comments:
CREATE TABLE IF NOT EXISTS comments (
disquss_id uuid, //some disqussion
comment_id timeuuid,
created_at timestamp,
user_id uuid,
comment_text text,
PRIMARY KEY ((disquss_id), user_id, comment_id),
) WITH CLUSTERING ORDER BY (comment_id DESC);
If we want to add replies function, i see two ways to do it:
make field replies as map type, for example replies map<uuid, reply>, or make another table replies such
CREATE TABLE IF NOT EXISTS replies(
parent_comment_id timeuuid, //comment_id from table `comments`
comment_id timeuuid,
created_at timestamp,
user_id uuid,
comment_text text,
PRIMARY KEY ((parent__comment_id ), user_id, comment_id),
) WITH CLUSTERING ORDER BY (comment_id DESC);
First question:
Option with map field give me advantage to get all replyes at once, but option with table replies give advantage of pagination. If we expect, that there will be 10000 replies on one comment, creating a new table is best option. Am i right?
Second question: If we decide to use second option with another table replies, what best practice to get that replies for comments? If we took 100 first comments, i must make 100 another request to get replyes for that comments. It doesn't seem like the best solution and i'm very confused
Third question: Extending the second situation, if we decide to make function for like comments, obviously me must use counters. We cannot mix counter and non counter columns in the same table, thats why we must created another table 'comments_like'. In that case we must to make request to database for every single comment. What to do in that case?
Thanks for any suggestion!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
