Skip to content

Twitter with pull-only timelines and Cassandra

Arjun RaoPosted · 1 min read

What if you never fan out at all? A pull-only design keeps writes trivial and pushes all the work to read time, which Cassandra handles better than you might expect.

Data model#

CREATE TABLE tweets_by_user (
  user_id bigint,
  tweet_id timeuuid,
  body text,
  PRIMARY KEY (user_id, tweet_id)
) WITH CLUSTERING ORDER BY (tweet_id DESC);

Reading a timeline means querying the newest tweets of everyone you follow and merging them, a k-way merge over sorted partitions.

When it works#

Pull-only is a good answer when the follow graph is small or reads are rare. At Twitter's read volume it needs an aggressive cache in front, at which point you are halfway to fan-out on write.

Text by Arjun Rao, licensed under CC BY-SA 4.0. You may share and adapt it with credit to the author, under the same licence.

Other approaches to Design Twitter

Submit your approach

Comments

Loading comments…