Guide

Hybrid fan-out uses push for ordinary authors and pull for celebrities. A normal post is pushed into follower timelines, so reads stay fast. A celebrity's post goes into one small list of recent posts, and the feed merges that list in when a user loads the page. The threshold between the two is the key decision.

Concept

This page builds on fan-out on write and read and timeline storage. A celebrity here means an author whose follower count is above a threshold.

The big idea

Pure push is cheap for the author and expensive for a huge account. Pure pull is cheap for huge accounts and expensive for every reader. The hybrid splits the work by follower count. Ordinary authors pay a small write cost when they post. Celebrities pay nothing on the write path, and the read path merges their few recent posts.

Think of a mailing list. A personal note goes into each person's inbox. A famous person posts once on a public noticeboard, and anyone who wants it checks the board. The picture breaks because the merge is real CPU work done on every feed load.

Walking through it

The routing rule is simple:

if follower_count < THRESHOLD (around 100k):
    push the post to each follower's timeline cache
else:
    mark the author as "pull" (celebrity)
    on feed read: merge the cached timeline with the celebrity's recent posts

Now a worked example. A user follows 200 accounts, 3 of whom are celebrities. Their timeline holds about 800 post IDs from the other 197. When they load the feed:

  1. Read the top of the timeline. That gives the ordinary posts.
  2. Read about 20 recent IDs from each of the 3 celebrity lists. That is 60 candidates.
  3. Merge the candidates by timestamp, keep the newest 20, and hydrate them.

No 100 million writes happened when the celebrity posted. The cost moved to a small merge on the next read.

The design for celebrities has four parts:

  1. Flag accounts above the threshold, either with a stored flag or from the follower count.
  2. Skip push for them.
  3. Keep recent:{authorId}, a small sorted set of the last 100 to 500 posts. Updating it is one write.
  4. Merge those lists into the feed on read, and monitor push lag as its own metric.

Trade-off

Default to hybrid. Push keeps the common read path fast, and pull or merge isolates the celebrity problem. The threshold is a knob. If fan-out lag grows, lower it so more authors switch to pull. If merge CPU on reads grows, raise it so fewer authors need a merge.

Common mistakes

  • Iterating a celebrity's follower list. Never scan it for push. Store the follower count separately.
  • Backfilling celebrity posts into timelines on follow. The merge already covers them, so backfill only copies data.
  • Setting the threshold once and forgetting it. Traffic changes, so check the threshold against lag and merge CPU.

Check yourself

  1. A celebrity with 100 million followers posts once. How many timeline writes happen on the push path?

    None. The post goes into one recent-posts list, and the push path skips the author.

  2. If fan-out lag keeps growing, which way should the threshold move?

    Lower it. More authors switch to pull, so the push path does less work.

Key takeaways

  • Push is for ordinary authors. Pull, merged on read, is for celebrities.
  • The threshold trades write lag against read-time merge cost.
  • A celebrity's recent-posts list is small, so the merge stays cheap.
  • Track push lag and merge cost as separate metrics.

Further learning

Next: feed ranking, which covers how the candidates get ordered.