数据库设计 - “推送”模型或扇出字段 [英] Database Design - "Push" Model, or Fan-out-on-write

查看:191
本文介绍了数据库设计 - “推送”模型或扇出字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景信息

我正在尝试检索我关注的人的图片,按照最新时间排序。这就像一个twitter新闻饲料,他们显示你的朋友最新的饲料。

I'm trying to retrieve images from people I follow, sort by latest time. It's like a twitter news feed where they show the latest feed by your friends.

计划:

目前我只需要保留一个项目考虑,这是图像。在未来,我打算分析用户的行为,并将他们可能喜欢的其他图片添加到他们的Feed等。

Currently there is only 1 item i need to keep in consideration, which is the images. In future i'm planning to analyse user's behavior and add in other images they might like into their feed, etc.

http://www.quora.com/

http://www.quora.com/What-are-best-practices-for-building-something-like-a-News-Feed

我个人觉得拉模型,或者说,风扇输出负载,其中我实时拉所有信息将是最糟糕的推模型。因为想象我有100个以下,我将不得不提取和排序的时间。 (让我知道如果我错了,例如,读是比写(推模型)100倍

I personally feel that "Pull" Model, or Fan-out-on-load where i pull all info at real time would be worst than the push model. Because imagine i have 100 following, i would have to fetch and sort by time. (Let me know if i'm wrong eg, Read is 100x better than Write(Push Model)

我推动的推模型的当前设计如下

The current design of the push model i have in mind is as follows

Table users_feed(ID, User_ID, Image_ID,datetime)

选项1:存储Image_ID列表

Option 1 : Store A list of Image_ID

存储一个图片ID和重复的行(更多具有相同User_ID但不同Image_ID的行)

Option 2 : Store one image ID and duplicate rows(More Rows of same User_ID but different Image_ID)

计划是限制用户在此Feed中可以拥有的每一行,这意味着,总是会有最多50张图片,如果他们想要更多的项目超过50图像在他们的新闻源。他们不能(我可能编码一个替代存储更多,以便将来可以查看更多)

The plan is to limit each Row a user can have in this feed , which means , there would always be a max of 50 images. If they want more items beyond the 50 images in their news feed. They cant(I might code a alternative to store more so they can view more in future)

问题1

由于当用户关注用户将一个项目添加到他们的

Since when user following users add a item into their "collection" i have to push it into each of their follower's feed. Wont there be a problem in Write? 200 followers = 200 writes?

问题2

哪种方法对我来说会更好,因为我只有一种类型的数据是图像。图片的Feed。

Which method would be better for me keeping in consideration that i only have one type of data which is images. Feeds of images.

问题3

如果我选择存储Feed提前(推方法)我怎么实际写它到我所有的朋友?

If i choose to store the feed in advance(push method) how do i actually write it into all my friends?

Insert xxx into feeds whereIn (array of FriendsID)?

任何形式的意见将非常感谢。提前感谢!

Any form of advice would be greatly appreciated. Thanks in advance!

推荐答案

我建议您按拉方法 ,原因如下:

I would recommend you to follow pull method over push method for the following reasons:


  • 这将为未来的扩展提供更多自由。

  • It gives to more freedom for extencibility in the future.

减少写入次数(假设有10M个关注者,则必须有

,10M只写入1个帖子)。

Less number of writes ( imagine 10M followers then there has to be
10M writes for just 1 post).

您可以通过类似于以下查询获取用户的所有Feed:

You can get all feed of a user simply by query similar to:

SELECT * FROM users_feed as a WHERE a.user_id in < // select all
user_ids of loged in user //>)

SELECT * FROM users_feed as a WHERE a.user_id in ( < //select all user_ids of followers of loged in user// > )

(语法不跟随表
结构的追随者是不知道)

(Syntax not followed as table structure of followers is not known)

这篇关于数据库设计 - “推送”模型或扇出字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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