Sample Header Ad - 728x90

How do I model a Cassandra table that stores friends of a user?

1 vote
1 answer
402 views
Recently I started to learn Cassandra. I needed to design the database for my web application. So, I prepared conceptual data model as well as application workflow, and currently I’m stuck on something… Let me provide you with some details of the issue. Well, I want to show all friends of currently logged-in user WITH PROFILE PICTURES AND THEIR FULL NAME. So I probably need two tables: Fragment of Application Workflow
**users_by_id**
user_id PARTITION KEY
email
password
profile_image
full_name
**friends_by_user_id**
user_id PARTITION KEY (whose friend is it)
friend_id (user id of the friend)
And now let’s say I want to display all friends in a list, but the problem is the user expects the app to show their profile pictures and their full name (not just the friend‘s user id), so the user can recognize who is who (pretty logical, right?). So, how do I do that? I mean I could get the users id and then query the users table to finally get the full name and profile picture individually. Although, I don’t think it would be very efficient (because what if the user have hundreds of friends?!). ***EDIT: or what if the friend changes their profile picture or name?*** What is the right way to solve this problem? Thanks in advance!
Asked by Jacobino (11 rep)
Nov 21, 2022, 07:12 PM
Last activity: Apr 16, 2025, 08:04 AM