Part VI — The Blueprint · Lesson 11.4
HLD – News Media Feed (Facebook, Twitter)
In one lineA cursor-paginated list that must accept live inserts without ever moving content under the reader.
Where you've seen itThe "12 new posts" pill at the top of a timeline — the polite alternative to yanking the page.
Diagram
| Step 1–2 | Scope and scale |
|---|---|
| In scope | timeline · post detail · compose · like/repost/reply |
| Out of scope | DMs · search · trends · ads · moderation |
| Scale | 300M DAU · ~50 posts/session · live updates every few sec · mixed media, mostly text + one image |
Lessons in this diagram6.6 Normalization
Lessons in this diagram10.13 Real-Time Updates
6b · DEEP DIVE — WHY OFFSET PAGINATION BREAKS HERE
offset page 2 returns posts already seen, because 12 new
posts shifted every index (10.11)
cursor after=<p7> → always the item AFTER p7,
regardless of what arrived above it
Cursor = base64(rankScore | postId) so it survives
ranked (non-chronological) feeds too.How it works
- Cursor pagination everywhere; offsets are unusable on a feed that receives inserts.
- Normalized store so one
post.likedevent updates the post in the timeline, the detail view, and the profile at once. - Buffer live inserts behind a pill; auto-insert only when the user is genuinely at the top.
- Virtualize past a few hundred items (10.7), and preserve scroll position on back-navigation.
- Optimistic like and repost with rollback; the counter is derived, never separately stored.
Trade-offs
| Choice | Cost |
|---|---|
| Buffered inserts | Feed is briefly stale by design |
| Ranked (non-chrono) feed | Cursor must encode the rank score |
| Virtualization | Loses native in-page find, complicates SEO |
| SSE for updates | One-way only — compose still uses REST (2.5) |
Interview angle
"New posts arrive while the user is reading. What do you do?"
- Buffer them and show a count pill; only insert automatically when scroll is at the very top.
- Use cursor pagination so those inserts don't cause duplicates on the next page fetch.
- Patch by id into a normalized store, so a like on one post doesn't re-render the entire list (10.5).
Recap
- Cursor pagination is mandatory the moment items can be inserted.
- Never move content under someone who's reading — buffer and offer.
- Normalize, so one event updates every view of that entity.