News Feed
The Twitter/Instagram timeline, worked through the TOGAF ADM phases — with the fan-out decision landing in Phase D.
News feed, the ADM way, in 30 seconds
- A (Vision): a fast, always-fresh-enough home timeline; principles — read-optimized, resilient to viral spikes, eventually consistent.
- B (Business): capabilities — publish a post and read my feed; reading dominates massively.
- C (Data/App): per-user feed = a list of post IDs; posts stored once; stateless app tier.
- D (Technology): the heart — the fan-out decision (push vs pull vs hybrid), feed cache, async workers, sharding.
- E–H: ship push-based feeds first, add pull-for-celebrities, then governance via SLOs on feed freshness and load.
- Lesson: the celebrity problem, surfaced in Phase B, forces the hybrid design in Phase D — the method connects them.
A personalized newspaper, printed for everyone
Imagine a newspaper where every single reader gets a different front page, made only of stories from the people and topics they chose to follow, freshest first. That's a news feed. The twist that makes it hard: there are hundreds of millions of readers, each one opens their paper dozens of times a day, and a popular columnist might be followed by fifty million of them at once. Somebody has to decide when to assemble each person's front page — and that one timing decision is the whole problem.
There are only two honest ways to assemble that front page. You can print it the moment a story is written, stuffing it into every follower's paper ahead of time, so opening the app is instant. Or you can print it the moment the reader opens the app, gathering their followees' latest stories on demand. The first is fast to read but brutal when a celebrity posts (fifty million papers to update for one story). The second is cheap to write but slow to read. The real design is choosing which strategy for which users — and that's exactly where the ADM lands us.
What makes it hard — the problem before the solution
- Reads massively outnumber writes. People scroll far more than they post, so the read path must be the fast one.
- One post can have millions of recipients. A celebrity's single post is cheap to store but ruinous to copy into fifty million feeds.
- Freshness matters, but not to the millisecond. A post showing up a few seconds late is fine — and that slack is what lets us do the expensive work in the background.
- Feeds can't store full posts. If every feed held full copies, one edited or deleted post would mean hunting through millions of feeds to fix it.
Why the ADM suits this problem
The feed's hardest choice — when to do the fan-out work — is easy to get wrong if you jump straight to technology. Walking the ADM forces the celebrity-scale problem to surface in Phase B (business capabilities and scale), so that by Phase D the hybrid fan-out is an obvious consequence rather than a lucky guess.
Phase A — Architecture Vision
- Vision: show each user a timeline of recent posts from people they follow, fast, at hundreds of millions of users.
- Stakeholders: readers (want instant, fresh-enough feeds), posters (want their post to reach followers), the business (wants it to survive viral moments cheaply).
- Principles: read-optimized first (reads dwarf writes); survive celebrity-scale accounts; eventual consistency is acceptable (a post can appear a few seconds late).
Phase B — Business Architecture
- Value stream: user posts → followers' feeds update → a follower opens the app → sees recent posts.
- Capability 1 — Publish a post: moderate volume; one write per post.
- Capability 2 — Read my feed: enormous volume; every app open is a feed read.
- The scale landmine: a single celebrity with tens of millions of followers. Surface it now — it will dictate Phase D.
Phase C — Information Systems Architecture (Data & Application)
Data architecture
- Posts are stored once in a post store (ID, author, content, timestamp).
- A user's feed is a list of post IDs, not full posts — so editing or deleting a post doesn't mean hunting through millions of feeds.
- Social graph (who follows whom) is its own store, queried during fan-out.
Application architecture
- Stateless app tier for publish and read, scaling horizontally.
- An async fan-out pipeline (queue + workers) so posting returns instantly.
- A read-time assembly step that hydrates post IDs into full content, in one batched lookup.
Phase D — Technology Architecture (the core)
Now the concrete design. The central decision — fan-out — gets its own deep step.
D1 — Estimate the load
# 300M daily users, ~10 feed opens/day
reads_per_sec = 300_000_000 * 10 / 86_400 # ~35,000 feed reads/sec
# ~2 posts/user/day
writes_per_sec = 300_000_000 * 2 / 86_400 # ~7,000 posts/sec
# The landmine, quantified:
# 1 celebrity post, 50M followers, fan-out on write = 50M feed writes. Per post.D2 — The fan-out decision (the heart)
| Fan-out on write (push) | Fan-out on read (pull) | |
|---|---|---|
| When work happens | At post time — write into every follower's feed | At read time — gather followees' posts and merge |
| Read speed | Instant — feed is pre-built | Slower — gather + merge live |
| Write cost | Huge for popular accounts | Cheap — store the post once |
| Best for | Normal users | Celebrities with massive followings |
- Decision — hybrid: push for normal users (instant reads), pull for celebrities (avoid millions of writes).
- At read time, merge: a user's pre-built pushed feed + a live pull of the few celebrities they follow, ordered by time.
- 'Celebrity' = a follower-count threshold you tune — the one knob that separates the two paths.
Why hybrid, and why not just pick one?
The tempting move is to pick a single strategy and be done. Both single-strategy answers hit a wall, and naming the wall is what earns the point.
Pure push (fan-out on write) fails on the celebrity. When someone with fifty million followers posts, you have to perform fifty million feed writes for that one post. Do that for every celebrity post and your write system drowns — a single tap by one account can generate more work than the entire rest of the platform. The gap push can't fill is the long tail of enormous accounts.
Pure pull (fan-out on read) fails on the ordinary read. If nothing is pre-built, every time anyone opens the app you must fetch the recent posts of everyone they follow and merge them live. For a user who follows 500 accounts, that's 500 lookups per app-open, multiplied by hundreds of millions of opens a day. The gap pull can't fill is the sheer volume of reads.
The hybrid wins because the two failure modes don't overlap. Ordinary accounts have few followers, so pushing their posts is cheap — and it makes the common read instant. Celebrities have few posts relative to their reach, so pulling their handful of recent posts at read time is cheap — and it dodges the fifty-million-write explosion. You use each strategy exactly where its cost is low, and merge the two at read time.
| Strategy | Where it's cheap | The gap it can't fill |
|---|---|---|
| Pure push | Ordinary posters; instant reads. | A celebrity post = millions of feed writes; the write tier drowns. |
| Pure pull | Rare posters; trivial writes. | Every app-open fans out to hundreds of followee lookups; reads drown. |
| Hybrid (chosen) | Push the many cheap posters, pull the few huge ones. | Needs a tuned follower threshold and a read-time merge — worth it. |
def get_feed(user_id):
# 1. Pre-built feed from fan-out-on-WRITE (normal authors pushed here).
pushed_ids = feed_cache.get(user_id) # list of post IDs, already there
# 2. Fan-out-on-READ for the few celebrities this user follows.
pulled_ids = []
for author in follows_who_are_celebrities(user_id): # above the follower threshold
pulled_ids += recent_posts(author, limit=20)
# 3. Merge both sources, newest first, then hydrate IDs into full posts.
merged = sort_by_time_desc(pushed_ids + pulled_ids)[:50]
return batch_get_posts(merged) # one batched lookupD3 — Where feeds live (caching)
- Per-user feed lists live in an in-memory cache (see Caching) so reads are instant.
- Store IDs only; hydrate post content from the post store on read.
- This directly realizes the Phase A read-optimized first principle.
D4 — Async fan-out (messaging)
- Pushing to 10,000 followers can't happen while the poster waits, so publish just accepts the post and emits an event to a queue (see Message queues).
- Workers consume the event and spread the post ID into follower feeds in the background.
- This is why a post may take a few seconds to appear — the trade we pre-approved in Phase A.
def on_post_published(event):
author, post_id = event.author, event.post_id
if follower_count(author) >= CELEBRITY_THRESHOLD:
return # celebrity: skip push, handled at read time
for follower in followers_of(author): # could be thousands — hence async
# Prepend the ID to each follower's cached feed and cap its length.
feed_cache.lpush(f"feed:{follower}", post_id)
feed_cache.ltrim(f"feed:{follower}", 0, 999) # keep only the newest 1000D5 — Sharding & the edge
- Shard feeds by user ID (see Sharding) so load spreads across nodes.
- Front the read API with a load balancer; serve static media via a CDN (see CDN).
- Autoscale the fan-out worker fleet for viral spikes.
D6 — Cross-cutting concerns
- Ranking (if required): the fan-out produces candidate posts; a scoring layer ranks them per user, with a chronological fallback if the ranker is slow.
- Consistency: eventual — accepted in Phase A (see Consistency models).
- Observability: track feed-build latency and fan-out lag; alert when posts take too long to appear.
Scaling & bottlenecks — what breaks first
Turn the dial up and the feed fails in a predictable order. The first thing to buckle is almost never the read path — it's the fan-out, because that's where one action multiplies into millions.
| Breaks first as you scale | The symptom | The fix |
|---|---|---|
| Fan-out worker lag | Posts take minutes, not seconds, to appear in followers' feeds. | Autoscale workers; shard the queue; raise the celebrity threshold so fewer posts push. |
| A viral ordinary account | Someone just under the threshold suddenly has huge reach. | Make the threshold dynamic; promote hot accounts to the pull path on the fly. |
| Feed cache memory | Storing 1000 IDs × hundreds of millions of users overflows RAM. | Cap feed length harder; evict inactive users; store IDs, never full posts. |
| Read-time merge cost | Users following many celebrities do many live pulls per open. | Cache each celebrity's recent posts once and share that across all their followers. |
The subtle one is the last row: a celebrity's recent posts are pulled by all their followers, so you pull them once, cache that small list, and let every follower's merge read the same cached copy. One pull serves millions of reads — the pull path's own version of 'do the expensive work in one place.'
def recent_posts(author, limit=20):
key = f"celeb_recent:{author}"
cached = feed_cache.get(key)
if cached is not None:
return cached[:limit] # millions of followers reuse THIS one copy
posts = post_store.recent_by_author(author, limit)
# Short TTL: fresh enough for a feed, but one DB read serves everyone until it expires.
feed_cache.set(key, posts, ttl=30)
return posts
# Without this cache, N followers would each pull the same celebrity posts N times.Phases E & F — Migration Planning
- Ship push-based feeds first for all users — simplest path to a working timeline.
- Add the pull-for-celebrities path once the threshold and merge logic are proven.
- Layer ranking last, behind a flag, so a slow ranker can be disabled without breaking the feed.
Phases G & H — Governance & Change
- Governance (G): SLOs on feed-read p99 and on how quickly a post appears in followers' feeds; capacity policies for viral events.
- Change (H): adding feed types (e.g. a 'following-only' view) is a bounded change on top of clean boundaries, not a re-architecture.
The feed is a lesson in doing expensive work at the right time — and the ADM is what makes that timing decision traceable rather than lucky.
Why it matters
- It forces the precompute-vs-compute-on-demand trade that recurs across system design.
- It shows why one design rarely fits all users — the celebrity case demands a hybrid, surfaced early by the method.
- It connects caching, async messaging, and eventual consistency into one coherent, phase-ordered system.
If ignored
- Skip Phase B's scale analysis and you pick a pure fan-out that melts on celebrity accounts.
- Store full posts in feeds and edits/deletes become a nightmare across millions of copies.
- Fan out synchronously and posting grinds to a halt at scale.
Where it fits
- Phase D holds the fan-out decision, feed cache, async workers, and sharding.
- Phase A/B supply the principles and the celebrity landmine that drive D.
- Sits beside the interview framework as a second way to structure the answer.
Related topics
- TOGAF in practice: the full enterprise version of this ADM method
- Caching: pre-built feeds live in cache for instant reads
- Message queues: powers the async fan-out in Phase D
- Sharding: feeds shard by user ID to spread load
Interview lens
Questions it unlocks
- Design Twitter's / Instagram's home timeline.
- Fan-out on write or on read — which and why?
- How would TOGAF's ADM structure this design?
60-second answer
I frame it as an ADM walk. Phase A sets principles — read-optimized, survive celebrities, eventual consistency OK. Phase B finds two capabilities, publish and read, with read dominating, and surfaces the celebrity-with-50M-followers landmine. Phase C models a feed as a list of post IDs in cache with posts stored once. Phase D is the core: hybrid fan-out — push for normal users so reads are instant, pull for celebrities to avoid millions of writes, merged at read time — with async workers behind a queue, feeds sharded by user ID, and ranking as an optional scoring layer. E–H ship push first, add pull, then govern with freshness SLOs. The power is that the hybrid in D is a direct consequence of the celebrity problem found in B.
Common traps
- Jumping to a fan-out strategy before Phase B reveals the celebrity scale problem.
- Storing full posts in every feed instead of lightweight IDs.
- Fanning out a celebrity's post synchronously to millions of feeds.