简体   繁体   中英

How does facebook store the friends of a user?

I am wondering how exactly the information that a user with id x is friends with users with ids z,y,w is stored in a very large scale app like facebook.

I am thinking of several possibilities

a) Have a table which maps friendships with the ids of the people involved as foreign keys, as shown here:

Person|isFriendsWith

x -------------------y

x ------------------ z

x------------------- w

Which seems to me it wouldnt scale well at all.

b) Have a field in the users row that stores the ids of their friends in a kind of serialized format like a string "#z#y#w". I suppose with the right algorithm the parsing and updating of this string would be easy.

c) Have a separate table with the friends of each user. Would this be too much load on the server?

d) Something else?

So, if anybody knows what facebook does and can share details it will be appreciated, that's what the question is about. Also, if someone can share insight why what I listed here would not scale well or would have other problems performance-wise, I am interested in hearing it.

Thanks

Here are some links. The first link's page has a link in it on the words "largely complex" that link to a flickr image of a schema. I cannot vouch for the correctness of any of the information in these links:

http://www.makeuseof.com/tag/facebook-work-nuts-bolts-technology-explained/

http://www.theregister.co.uk/2011/07/13/mike_stonebraker_versus_facebook/

http://gigaom.com/cloud/facebook-trapped-in-mysql-fate-worse-than-death/

http://snarfed.org/facebook_data_store_api_thoughts/

The image I mentioned was created by analyzing the business entities in the API that Facebook has opened up. http://blogs.x2line.com/al/archive/2007/06/02/3124.aspx That was 2007, so may or may not be representative any longer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM