Answer the question
In order to leave comments, you need to log in
How is the "like" system implemented in social networks?
Let's say 1,000,000 users rated a photo. How is it implemented? How is data stored?
Answer the question
In order to leave comments, you need to log in
The question of how to store likes is quite simple :)
0. All users are divided into groups (nodes). Each node is assigned a server that serves it. Further, the structure of the base is built for specific functional cases.
Suppose we need to repeat the standard facebook/vk counter.
What are the cases?
1. Show the number of likes for a photo.
Easy - put the counter in the properties of this photo in the node of its author.
2. Determine if the user liked this photo.
We store a pair (user_id, photo_id) in the node of the user who did the like
3. Add/delete likes
cm p2 + update the counter in the node of the author of the photo.
4. Display the last likes of
Cash in the photo properties.
etc.
On a live project, everything will be complicated by "bad" users - those who have 1,000,000 photos and those who made 1,000,000 likes. This is solved not by uniform, but by intelligent distribution of users across nodes.
PS
The task of forming a news feed is much more difficult :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question