facebook 架构
How your social media data on Facebook are organized and stored
如何在Facebook上组织和存储您的社交媒体数据
There is no need for an introduction to Facebook. Facebook has more than 1 billion active users who record their relationships, share their interests, upload and comment on text, images and videos. In this blog, I will mainly discuss two aspects of Facebook’s backend system:
无需介绍Facebook。 Facebook拥有超过10亿活跃用户,他们记录他们的关系,分享他们的兴趣,对文本,图像和视频进行上传和评论。 在此博客中,我将主要讨论Facebook后端系统的两个方面:
- How the social graph is modeled and stored, that is, the database schema adopted by Facebook. 社交图的建模和存储方式,即Facebook采用的数据库架构。
- How Facebook scaled its infrastructure, including servers, cache and databases, to serve 1 billion reads and millions of writes per second. Facebook如何扩展其基础结构(包括服务器,缓存和数据库),以每秒处理10亿次读取和数百万次写入。
社会图的数据模型 (The Data Model For Social Graph)
Facebook stores majority, if not all, of users’ data, such as profiles, friends, posts and comments, inside a single giant social graph. There are two elements inside a social graph, nodes and edges.
Facebook在单个巨型社交图谱中存储用户的大部分(如果不是全部)数据,例如个人资料,朋友,帖子和评论。 社交图中有两个元素:节点和边。
- A node represents an entity, such a user, a post, a comment and a location. 节点代表一个实体,例如用户,帖子,评论和位置。
- An edge represents the relationships between the nodes. For example, one edge could mean that a particular user created a particular post. 一条边表示节点之间的关系。 例如,一个边缘可能意味着特定用户创建了特定帖子。
For example, let’s imagine that the user Alice creates a post and tags the user Bob, as illustrated below. The user Cathey comments on the post, which David likes.
例如,假设用户Alice创建了一个帖子并标记了用户Bob,如下所示。 用户Cathey在帖子中发表了评论,David很喜欢。
Alice: It was a great party! @ Bob
爱丽丝:那是一场很棒的聚会! @鲍勃
— — Cathey: Thanks for coming. (David likes this)
— — Cathey:谢谢您的光临。 (大卫喜欢这个)
The post, comment and like will result a few changes to the social graph, as illustrated in the figured below. Assume the users, Alice, Bob, Cathey and David are already friends. Inside the social graph, 4 nodes already exist, 1 for each user. For instance, the node representing the user Alice has ID 105 and otype as User. (otype is an abbreviation for object type. Inside the Facebook system, node is referred to as object.) There are 2 edges between each pair of the users t