I'm preparing for a mid-level system design interview and want to keep the design understandable, especially the news feed. Are there any useful articles or videos that explain it without relying on a lot of unfamiliar technology?
What should I study for a Twitter clone interview using a relational database?
Answers
Start with a relational model you can explain: users, follows with follower and followee IDs, and posts with an author ID, creation time and content. For a basic feed, query recent posts from the accounts a user follows, ordered by creation time.
That is fan-out on read. It keeps writes straightforward, but assembling the feed can get slower when someone follows a lot of accounts. You can then introduce a feed_entries table as an alternative: create entries for followers when a post is published, so reads are cheaper. The cost shifts to writes, particularly for accounts with huge follower counts.
For the interview, I'd begin with the simple version and explain why you might change it. You don't need to introduce every possible component up front.
Reply to this answer
Try ByteByteGo's Design a News Feed writeup and Grokking the System Design Interview. Look specifically for the discussion of fan-out on read versus fan-out on write. That tradeoff gives you a useful framework for explaining the feed, even if you stick with a relational database for your initial design.
Reply to this answer
There's also a video called Postgres for Everything, or something close to that. It may be useful for thinking about what you can do with a relational database before adding unfamiliar services. I'd treat it as background rather than a complete news feed walkthrough.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Drelvik-3a:
A hybrid is worth mentioning too. Precompute feeds for ordinary accounts, but pull posts from very large accounts when the feed is read.