Push or pull feeds when one account has 3 million followers?
Question
You build the home feed of a social app. Two classic designs:
- Push (fan-out on write): when someone posts, add the post id to the feed list of every follower.
- Pull (fan-out on read): when someone opens the feed, fetch the recent posts of everyone they follow.
Two authors, per day:
| author | followers | posts | open the app | feed opens each |
|---|---|---|---|---|
| Ana | 300 | 2 | 80% | 6 |
| City News | 3,000,000 | 10 | 5% | 4 |
- For each author, count push writes and pull reads per day. One read fetches one author's recent posts.
- City News is pushed at 50,000 writes a second. How long until one post reaches every follower?
- Which design do you pick?
Show hints (3)
- "COUNT BOTH SIDES"
Push writes once per post per follower, active or not. Pull reads only when a follower opens the feed.
- "LOOK AT ONE POST"
Daily totals hide the burst. One City News post is 3,000,000 writes at once. Who waits while they run?
- "MIX THE TWO"
Must every author use the same design? What if you pull the few huge accounts and merge them into a pushed feed?
Show checked explanation
A hybrid. Push posts from normal authors like Ana, so the feed is ready when it opens. Pull the few huge accounts like City News when the feed opens, and merge their posts in. Pushing City News means 3 million writes per post, mostly to feeds nobody opens.
authors = { # followers, posts a day, share who open the app, opens each
"Ana": (300, 2, 0.80, 6),
"City News": (3_000_000, 10, 0.05, 4),
}
WRITES_PER_SECOND = 50_000
for name, (followers, posts, active, opens) in authors.items():
push_writes = posts * followers
pull_reads = round(followers * active * opens)
print(f"{name}: push {push_writes:,} writes, pull {pull_reads:,} reads")
seconds = authors["City News"][0] / WRITES_PER_SECOND
print(f"one City News post: {seconds:.0f} s of fan-out")Ana: push 600 writes, pull 1,440 reads City News: push 30,000,000 writes, pull 600,000 reads one City News post: 60 s of fan-out
Code run on CPython 3.12 against the examples above. Checked by an editor other than the author.
Walkthrough
The daily numbers:
| author | push writes | pull reads | cheaper |
|---|---|---|---|
| Ana | 600 | 1,440 | push |
| City News | 30,000,000 | 600,000 | pull |
Per follower, push costs one write per post, and pull one read per feed open. Ana's followers open the feed more often than she posts, so push wins, and each open is one fast read.
City News is the opposite. Only 5% of its followers open the app on a given day, so 95% of its 30 million daily writes go to feeds nobody reads that day. Each post is also a burst of 3,000,000 writes. At 50,000 a second, the last follower waits 60 seconds. Posts from other authors can wait behind it.
So use both. Authors under a follower limit push; bigger accounts don't. When a user opens the feed:
- Read their ready list of post ids.
- Fetch recent posts from the few big accounts they follow.
- Merge by time, drop duplicate ids, then load the post texts.
A user who follows 200 normal authors and 3 big ones makes 4 lookups, not 203.
The cost: every feed open by a City News follower now reads its post list, 600,000 times a day. The list is small and changes 10 times a day, so it caches well.
Common mistakes
- Copying the whole post into every feed. Store only post ids and load the texts when the feed opens. Then an edit or a delete changes one row, not 300 copies of Ana's post.
- Pulling for everyone. Someone who follows 200 people makes 200 lookups on every feed open. Reads get slow, and reads are what users wait for.
- Deciding from daily totals alone. If City News posted once a week, push would look cheaper: about 430,000 writes a day against 600,000 reads. Each post would still be 3 million writes at once.
- Fanning out inside the post request: the City News author would wait 60 seconds. Use background workers, and skip a post id already in the feed, so a retry adds no duplicate.
Follow-up questions
- "Where do you set the follower limit?" Start from a delivery target. Say a post must reach every follower within 10 seconds. At 50,000 writes a second, that allows up to 500,000 followers. Go lower if most followers are inactive or the feed store is busy, then measure.
- "Most followers of a big account rarely open the app. Can push still work?" Push only to followers active recently, for example in the last 7 days. When an inactive user comes back, build their feed by pull. Say 10% of City News followers were active that week: a post is then 300,000 writes, 6 seconds of fan-out, not 60.
What a strong answer covers
Counts both designs per author and picks a hybrid. Explains the burst and the wasted writes for a huge account. Shows the merge on feed open and sets the follower limit from a delivery target.
Open in interactive practice deck →