Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Facebook do it?

Have you ever noticed how facebook says “3 friends and 33 others liked this”? I was wondering what the best approach to do this is. I don’t think going through the friends list, and the list of users who “liked this” and comparing them is efficient at all! Do they keep a track of this in the database? That will make the database size very huge. What do you guys think?

Thanks!

like image 721
OneDeveloper Avatar asked Nov 29 '22 20:11

OneDeveloper


1 Answers

I would guess they outer join their friends table with their likes table to count both regular likes and friend likes at the same time.

With the proper indexes, it wouldn't be a slow query at all. Huge databases aren't necessarily slow, so there's really no reason to not store all of this information in a database. The trick is to make sure the indexes and partitions (if any) are set up well.

like image 147
Welbog Avatar answered Dec 04 '22 07:12

Welbog