One homepage load fetches hundreds of key value pairs at once.
A homepage shows posts. The posts have comments and likes, the comments have replies, and people click to see who has liked a post. A popular video is cached with its top comments and their top replies. There is no clear structure, because nobody can guess what users will find popular.
So the page is not cached as one piece. It is broken into levels:
- Level one. Notifications and popular posts, which everyone gets to see.
- Level two. The top 10 comments of a popular post, or the profile and mutual friends of a person to follow. It is cached too, and fetched only when the person clicks.
One homepage request fans out into nested calls: 95 keys for most requests and 1,700 for some. Facebook constructs a directed graph of the data. Some fetches run in parallel and some depend on others.
Updates follow read after write consistency. A like stays hit after a refresh, and an added comment shows on the post.