Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

How does Facebook calculate mutual friends?

Does it cache all mutual friends for each user? Does it use MySQL to calculate mutual friends with a query?

share|improve this question
1  
I've not used facebook, but I'll still guess they use some fairly standard graph theory technique. Take a look at en.wikipedia.org/wiki/Six_degrees_of_separation to get some ideas. –  Steve314 Jun 12 '11 at 17:57
3  
Facebook uses their proprietary graph database to do these calculations. A more interesting question would be how one could do them with a SQL (or other non-proprietary) database. –  Rein Henrichs Jun 12 '11 at 18:33
1  
It is an M-M relationship. Same question as: stackoverflow.com/questions/1009025/facebook-database-design –  Emmad Kareem Sep 10 '12 at 2:55

1 Answer 1

According to Facebook,

Mutual friends are the people who are Facebook friends with both you and the person whose profile you are viewing. For instance, if you are friends with Chris, and Mark is friends with Chris, then Chris will be shown as a mutual friend when you are viewing Mark's profile.

So, the set of mutual friends is the intersection of the set of your friends and the set of friends of the person you are viewing. If we assume that Facebook maintains an active cache of your friends, then when you view a person's page, another list containing that person's friends is retrieved, and the intersection of these two lists is the list of mutual friends.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.