【发布时间】:2015-03-22 22:13:33
【问题描述】:
我想要像 instagram 这样的设计时间线(主页),但大多数采样像 "twissandra-j" 使用波纹管模式:
-- Users user is following
CREATE TABLE following (
username text,
followed text,
PRIMARY KEY(username, followed)
);
-- Users who follow user
CREATE TABLE followers (
username text,
following text,
PRIMARY KEY(username, following)
);
-- Materialized view of tweets created by user
CREATE TABLE userline (
tweetid timeuuid,
username text,
body text,
PRIMARY KEY(username, tweetid)
);
-- Materialized view of tweets created by user, and users she follows
CREATE TABLE timeline (
username text,
tweetid timeuuid,
posted_by text,
body text,
PRIMARY KEY(username, tweetid)
);
在这个设计中,每插入一个新帖子,每个关注者都会在时间轴上插入一条新记录。如果一个用户有 10k 关注者和 1000 个用户使用应用程序,程序失败,有没有更好的方法?
// Insert the tweet into follower timelines
for (String follower : getFollowers(username)) {
execute("INSERT INTO timeline (username, tweetid, posted_by, body) VALUES ('%s', %s, '%s', '%s')",
follower,
id.toString(),
username,
body);
【问题讨论】:
标签: cassandra schema data-modeling nosql