如何在数据库中实现Facebook好友模块?
我正在为我的研究所开发一个 Facebook 类型的应用程序。
我被困在朋友模块了。即如何知道特定用户是否是某人的朋友。
我用谷歌搜索了很多,但没有得到任何满意的答案。 我得到的是:一个人会有很多朋友,在单独的表中实现用户和他们的朋友只会增加冗余和大的数据库大小。
我想到使用一个以顶点作为用户、以边作为连接的图。
但是如何在 db.
或者 Facebook 如何处理如此庞大的关系?
I am developing a facebook type application for my institute.
and I am stuck at the friends module. i.e. How to know if the particular users are one's friends.
I googled a lot but didn't get any satisfactory answers.
What I got is : there will be many friends of a person and implementing users and their friends in seperate table will only increase redundancy and large DB size.
I thought of using a graph with vertices as users and edges as connection .
But how to implement something like that in db.
Or How Facebook handles such huge amount of relationships?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我个人而言,我会为此创建一个专用表:
您可以有一个只有两列的表:userID 和friendID
由于数据库中用户之间的关系将是多对多,因此规范化它需要一个链接表,将其分为多对一对多
http:// dev.mysql.com/tech-resources/articles/intro-to-normalization.html#03
Personally, I would have a dedicated table for it:
You could have a table with just two columns: userID and friendID
Since the relationships between users in the db will be many-to-many, normalizing it requires a link table which breaks it into many-to-one-to-many
http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html#03
此类问题通常通过使用不同类型的数据库来解决。对于社交网络,图数据库应该有意义,因为节点和关系是社交网络中的一等公民。它。 Neo4j 图数据库,示例的完整源代码包含在标准下载包中。我还写了一篇博客文章 围绕这个主题,以另一个例子作为起点。
This kind of problems are usually solved by using a different type of database. For a social network, a graph database should make sense, as nodes and relationships are first class citizens in it. There's a social network example for the Neo4j graph database, the full source code of the example is included in the standard dowload package. I've also written a blog post on this theme, with another example as starting point.