Designing a Social Media Feed
The naive design breaks the moment one account gets a million followers — the fix is choosing a strategy per author, not globally.
Advanced
| Functional | Non-functional |
|---|---|
| Post a short update | Feed loads must be fast, even for a user following thousands of accounts |
| Follow/unfollow other accounts | The system must handle a small number of accounts with an enormous follower count without falling over |
| View a reverse-chronological feed of followed accounts' posts | New posts should appear in followers' feeds within seconds |
| Author's follower count | Strategy used | Why |
|---|---|---|
| Typical account (fewer than ~10K followers) | Fan-out-on-write (push) | The write cost is small and bounded, and it keeps feed reads for that account's followers fast. |
| Celebrity/high-follower account | Fan-out-on-read (pull) for that author specifically | Pushing to millions of followers on every post would be enormous write amplification for one post — instead, that author's posts are merged in at read time. |
| Requirement | How it's met |
|---|---|
| Fast feed loads at scale | Fan-out-on-write means most feed reads are a single fast key-value lookup, not a live fan-out query. |
| Doesn't collapse on celebrity accounts | Fan-out-on-read specifically for high-follower authors avoids write-amplifying a single post to millions of feeds. |
| New posts appear quickly | Pushed posts land in followers' feeds essentially at write time; pulled posts are fetched fresh at read time. |