新闻饲料数据库设计在Facebook [英] News feed database design as in Facebook

查看:109
本文介绍了新闻饲料数据库设计在Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使新闻Feed友好的数据库设计,以便它不会是非常昂贵的获得所有的项目(查询)放入新闻Feed?我唯一能想到的方法将涉及UNIONing几乎每一个表(代表组,笔记,朋友等)和获得日期等,似乎这是一个真正昂贵的查询运行为每个用户,它

How would make a news feed "friendly" database design, so that it wouldn't be extremely expensive to get all of the items (query) to put in the news feed? The only way I can think of would involve UNIONing nearly every table (representing groups, notes, friends, etc) and getting the dates and such, that just seems like it'd be a really expensive query to run for each user, and it'd be pretty hard to cache something like that with everyone's being different.

推荐答案

首先,考虑做一个性能原型来检查你的希望联合会太贵了。

Firstly, consider doing a performance prototype to check your hunch that the union would be too expensive. You may be prematurely optimisizing something that is not an issue.

如果这是一个真正的问题,请考虑一个纯粹用于保存事件Feed数据的表,该表必须更新与其他表并行。

If it is a real issue, consider a table designed purely to hold the event feed data, that must be updated in parallel with the other tables.

例如当创建注释记录时,还会在包含日期,描述和用户的事件表中创建事件记录。

E.g. when you create a Note record, also create an event record in the Event table with the date, description, and user involved.

考虑根据UserId(或UserId和Date)对事件表建立索引。也可以考虑在不再需要时清除旧数据。

Consider an indexing the Event table based on UserId (or UserId and Date). Also consider clearing old data when it is no longer required.

这不是一个规范化模式,但如果获取事件Feed是一个频繁的操作,可能会更快。

This isn't a normalised schema, but it may be faster if getting an event feed is a frequent operation.

这篇关于新闻饲料数据库设计在Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆