P
P
Peter2014-06-30 14:48:20
Social media
Peter, 2014-06-30 14:48:20

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

2 answer(s)
D
Dmitry Entelis, 2014-06-30
@DmitriyEntelis

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 :)

S
Stepan, 2014-06-30
@L3n1n

They create a database with the fields id_object + user_id who likes it.
If necessary, display all the likes of one photo, make a selection where object_id = id_of the desired photo.
Something like that on the fingers..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question