Part 7 of 8 · 2 min read
Trade-offs
Freshness, cost and a follow-up.
Trade-offs and what to say
| Choice | Gain | Cost |
|---|---|---|
| Push for most users | Fast reads | Wasted writes, hot keys |
| Pull for celebrities | No write burst | Slower, merged reads |
| IDs only in feed cache | Small memory | An extra hydration step |
| Queue for fanout | Fast publish, smooth load | Feeds can lag |
| Short feed list in cache | Low memory | Deep scroll hits the database |
Ranking. The book keeps the feed newest first. Real products rank posts by closeness and interest. That needs a scoring step between the feed cache and the answer, and usually a separate ranking service. Mention it as the next step.
Scaling talking points (from the book, each covered in earlier levels). Keep the web tier stateless. Cache as much as possible. Use several data centres. Loosen coupling with queues. Scale the database with replicas and sharding. Monitor peak queries per second and the time to refresh a feed.
Interview angle
Answer in your head first, then open it.
Push or pull?
Push for most, pull for accounts with huge followings, merged at read time.
Why only ids in the cache?
To save memory and avoid copies that go stale.
What if a celebrity posts?
No fanout. Followers pull and merge.
How do you handle a muted friend?
Filter in the fanout step and again at read time.
What do you monitor?
Queue depth of fanout, feed read latency, cache hit rate.
One follow-up to try. "Users complain that a deleted post still shows in feeds." A good reply: deletion marks the post in the content cache, and hydration skips marked posts. Ids left in feed lists are then harmless and fall out over time. A background job can also remove them. This avoids a costly sweep across millions of lists.
Check yourself: 1. What does ranking add? 2. Why is deletion cheap if hydration filters? 3. Name two metrics worth monitoring.
Words you will meet
| Word | Meaning |
|---|---|
| News feed | A list of posts from people a user follows |
| Fanout | Delivering one item to many receivers |
| Push and pull | Fanout on write and fanout on read |
| Hot key | A key that gets far more traffic than others |
| Hydration | Filling ids with full objects at read time |
| Graph database | A store for relations such as friendships |
| Hybrid | Push for most users, pull for very large accounts |
| DAU | Daily active users |