News Feed Cheat Sheet
Key concepts, trade-offs, and quick-reference notes for your interview prep.
Fanout-on-Write vs Fanout-on-Read
#1💡 Twitter uses push for normal users and pull for celebrities. State the hybrid model early in the interview to show you understand both trade-offs.
Celebrity Threshold: 10K Followers
#2Snowflake ID: Time-Sorted Unique IDs
#3💡 Snowflake IDs make timeline sorting free: ORDER BY id is the same as ORDER BY created_at, but without a secondary index on timestamp.
Timeline Cache: 800 Tweet IDs per User
#4Social Graph: Redis SET + MySQL
#5💡 Never write to Redis alone. Always write to MySQL first, then propagate to Redis via Kafka events.
Feed Ranking: Engagement Score
#6💡 We apply ranking at read time on the fetched timeline, not during fanout. Keep fanout simple (append ID). Rank on the way out.
Media: S3/CDN, Tweet Stores URL Only
#7💡 Upload media first, get the URL, then create the tweet with the URL attached. Two-phase: media upload is a separate API call.
Write Amplification: 1 Tweet = N Cache Writes
#8Read Path: Merge Cached + Celebrity Tweets
#9💡 This merge-at-read-time cost is the price we pay for not fanning out celebrity tweets. For 99% of users, it adds <10ms.