advanced
News feed
Choose fan-out-on-write or read, ranking, pagination, freshness, celebrity users, and cache invalidation.
News feeds balance fan-out-on-write (push model precomputing timelines) versus fan-out-on-read (pull model querying follows at read time). Push suits normal users with fast reads; pull or hybrid handles celebrities with millions of followers without write amplification.
Storage: per-user timeline cache, activity log of posts, ranking service, pagination cursors, and invalidation on new posts. Freshness targets drive cache TTL and partial precomputation.
On interviews: choose push versus pull for given follower distribution, explain celebrity problem, and sketch data model for timeline entries.
Common pitfalls: pure push for all users causing write storms; no ranking layer; pagination with unstable offsets under new posts.
The trade-off is flexibility versus complexity—know when the simpler path is enough.
Checklist:
- Select fan-out strategy by user tier.
- Design timeline storage and cache.
- Plan ranking and pagination cursors.
- Handle hot celebrities separately.