-1

In your opinion, how does facebook calculate mutual friends?

Has it cached all mutual friends for each user? Or does it let MySQL calculate through a query each time it displays them? Or does it make a query to the database and then calculate from a list? Or is there another way?

Letlhare
  • 3
  • 3
M4rk
  • 2,172
  • 5
  • 36
  • 70
  • 2
    They dont tell us stuff like this... But your MySQL calculation seems more likely. – Anirudh Ramanathan Jun 12 '11 at 16:33
  • 1
    possible duplicate of [Wondering how Facebook does the "Mutual friends" feature](http://stackoverflow.com/questions/2536891/wondering-how-facebook-does-the-mutual-friends-feature) – Ted Hopp Jun 12 '11 at 16:34
  • Maybe this question is more suited for http://programmers.stackexchange.com – cbrandolino Jun 12 '11 at 16:34
  • they're really doing computer science there. for any person you haven't visited before you can immediately see mutual friends. most probably they have a graph structure. but how they implement is really a serious topic and I bet many people continuously working on such algorithms of facebook. – ahmet alp balkan Jun 12 '11 at 16:41

1 Answers1

2

I believe it is pre-computed and not done when you load the page. How? There are a couple of options to look at this problem. A common way is to look at the data as a graph, where each person is a vertex, and an edge defines a friendship. Iterating through each existing pair of persons, and finding 2 edges paths. The vertexes you went over, are the mutual friends. If you really want to get into it, I would suggest starting with learning about Graph Theory

When dealing with such an amount of data, using MySql and queries won't work. On small amounts of data, it will.

Noam
  • 3,341
  • 4
  • 35
  • 64