【发布时间】:2014-02-19 12:01:50
【问题描述】:
只是为了好玩,我正在构建一个高音扬声器克隆以更好地理解 C*
我见过的所有建议的 C* 方案都使用或多或少相同的建模技术。问题是我对以这种方式建模 twitter 时间线的可扩展性表示怀疑。
问题: 如果我有一个非常受欢迎的用户A(摇滚明星)或更多用户,并且有 10k+ 用户关注,会发生什么? 每次用户 A 发布一条推文时,我们都必须在时间轴表中为他的每个关注者插入 10k+ 条推文。
问题: 这个模型真的会扩展吗? 任何人都可以建议我另一种方法来模拟可以真正扩展的时间线吗?
C* 架构:
CREATE TABLE users (
uname text, -- UserA
followers set, -- Users who follow userA
following set, -- UserA is following userX
PRIMARY KEY (uname)
);
-- View of tweets created by user
CREATE TABLE userline (
tweetid timeuuid,
uname text,
body text,
PRIMARY KEY(uname, tweetid)
);
-- View of tweets created by user, and users he/she follows
CREATE TABLE timeline (
uname text,
tweetid timeuuid,
posted_by text,
body text,
PRIMARY KEY(uname, tweetid)
);
-- Example of UserA posting a tweet:
-- BATCH START
-- Store the tweet in the tweets
INSERT INTO tweets (tweetid, uname, body) VALUES (now(), 'userA', 'Test tweet #1');
-- Store the tweet in this users userline
INSERT INTO userline (uname, tweetid, body) VALUES ('userA', now(), 'Test tweet #1');
-- Store the tweet in this users timeline
INSERT INTO timeline (uname, tweetid, posted_by, body) VALUES ('userA', now(), 'userA', 'Test tweet #1');
-- Store the tweet in the public timeline
INSERT INTO timeline (uname, tweetid, posted_by, body) VALUES ('#PUBLIC', now(), 'userA', 'Test tweet #1');
-- Insert the tweet into follower timelines
-- findUserFollowers = SELECT followers FROM users WHERE uname = 'userA';
for (String follower : findUserFollowers('userA')) {
INSERT INTO timeline (uname, tweetid, posted_by, body) VALUES (follower, now(), 'userA', 'Test tweet #1');
}
-- BATCH END
提前感谢您的任何建议。
【问题讨论】:
标签: twitter nosql cassandra data-modeling cql