user3489820
user3489820

Reputation: 1519

Cassandra - data modelling help needed

I try to design social network ( kind of ) application. I have a User, he has Follower(s), and there is a Timeline. My timeline table look like:

user_id
second_party_user_id
created
other_fields

So, when 'second_party_user' posts any new content, I get all people who follow him, and insert into their Timeline second_party_user's post. When user comes to see timeline, I do a simple request to his timeline by user_id. The problem is that I need to get ordered items. And if I want to get ordered by created, I need to put it as a second clustering column, not a third one. At the same time, if I put it as a second clustering column, ie:

user_id
created
second_party_user_id
other_fields

then I would have a problem when one user unfollows second_party_user, ie how can I delete by (user_id, second_party_user_id).

Any help will be highly appreciated! Thank you in advance.

Upvotes: 1

Views: 73

Answers (1)

dmarquina
dmarquina

Reputation: 4056

To handle those features you can use two tables, one for get the timeline ordered and another one to handle the elimination in both tables.

//order timeline by created date
user_id(pk) 
created(ck)
second_party_user_id 
other_fields

//with this table you can get created to delete in the first one and 
//delete this table with (user_id,second_party_user_id)
user_id(ck) 
second_party_user_id (ck)
created
other_fields

Upvotes: 2

Related Questions