Facebook 如何存储用户的好友?
我想知道 id x 的用户与 id z、y、w 的用户的好友信息是如何存储在像 facebook 这样的大规模应用程序中的。
我正在考虑几种可能性
a) 有一个表,将友谊与所涉及人员的 id 作为外键进行映射,如下所示:
Person|isFriendsWith
x ----------------- --y
x ------------------ z
x-------------------- w
在我看来这不会规模很好。
b) 在用户行中有一个字段,以某种序列化格式(如字符串“#z#y#w”)存储朋友的 id。我想使用正确的算法,解析和更新该字符串会很容易。
c) 与每个用户的朋友有一张单独的桌子。这会对服务器造成太大的负载吗?
d) 还有别的事吗?
因此,如果有人知道 Facebook 是做什么的并且可以分享详细信息,我们将不胜感激,这就是问题所在。另外,如果有人可以分享为什么我在这里列出的内容无法很好地扩展或在性能方面会出现其他问题的见解,我有兴趣听到它。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有一些链接。第一个链接的页面中有一个链接,上面写着“非常复杂”,链接到模式的 flickr 图像。我无法保证这些链接中任何信息的正确性:
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/
我提到的图像是通过分析 Facebook 开放的 API 中的业务实体创建的 向上。 http://blogs.x2line.com/al/archive/2007 /06/02/3124.aspx
那是 2007 年,所以可能不再具有代表性,也可能不再具有代表性。
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.