Skip to content
Back

social media app Database Design question

  • 1
  • Android
  • Web
  • Apple
moe
16 Nov, 2023, 19:32

,I'm creating a social media app using react Native I'm wondering what would be the best approach to store things like "like" and "follow" ? I heard that it's better to be on its own collection but is it really? also, thought about stroing basic things like doing that and also adding an attribute on the posts collection called "likesCount" whick reflects the count only, an Int, and keep the likes on its own collection, so that for time line view it will only get a count, not do another db request to get the likes collection, what do you guys think?

TL;DR
The user is seeking advice on the database design for a social media app. They have concerns about performance optimization, particularly for a feature similar to Twitter's "explore" section. They want to know if it would be better to store likes and follows in their own collection or within the posts collection. They are also considering using an attribute called "likesCount" in the posts collection to reflect the number of likes without making a separate database request. Solution: It is recommended to store likes and follows in their own collection for better performance and organization. This allows for easier querying and manipulation of the data. Additionally, using an attribute like "likes
D5
16 Nov, 2023, 20:54

For count, I think it's better to have the number in an attribute since it's never a good idea counting everything unless it's a small number

D5
16 Nov, 2023, 20:55

Respect likes in a collection, It's a good idea since that way you can query them

D5
16 Nov, 2023, 20:56

So you don't get all likes a post has, for example, you only get the ones from your friends or from your account to check if you liked it or not

D5
16 Nov, 2023, 20:57

Or just paginate tem

moe
16 Nov, 2023, 21:00

so you reckon, this approach is good? the posts are 5k+ and of course will grow, and I'm also using tanstack query to use some caching and get things to make sense, especially that I have a twitter-like "explore" where it basically gets 40 posts, doing infinite scrolling etc, so it's not from a specific friend or smth, so this neads to be heavily optimized for performance

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more