Design Google News - pull articles from 50,000 publishers, sort them by topic, and serve a personal feed and a top-stories list to 10 million readers in under 200 ms. One article is read by millions of people, so copying it into every reader's feed is the wrong shape. The staff-level signal is writing each article once onto shared lists and ranking a few hundred candidates per read, pulling every publisher on its own schedule, and keeping one viral publisher from taking over the front page.
Written by a Staff+ Engineer and an Engineering Manager
12+ years of experience in distributed systems and real-time messaging. Tech lead for large-scale chat applications serving billions of users. Over 12 years of industry experience with 6 years in engineering leadership, building and scaling tech infrastructure teams that deliver end-to-end large-scale distributed systems.
Finished this lesson?
Sign in to save your progress across devices.
Tip: use ← and → to move between lessons.
Was this lesson helpful?
Rehearse this exact question with the author
45-minute mock with a Staff+ engineer who interviews at your target company. Premium members save $20.
What to Design?
Could you answer these today? Tick what you already know.
The boxes are quick to draw: workers pull articles, a database keeps them, a service returns a feed. The interview is decided by four questions about what happens when 5 million articles a day meet 10 million readers. Each one is a deep dive later on this page, with three designs side by side: the one that sounds right, a better one, and the one that holds.
Swipe to see all columns
| The four questions, and the answer that sounds right | |||
|---|---|---|---|
| # | The interviewer asks | The answer that sounds right | What it misses |
| DD1 | Tech has 2 million followers. A new tech article arrives. What do you write? | Push it into every follower's feed, like a social network | An article is shared by millions: that is 58 million writes a second. Write it once onto a shared list, and build each feed when it is read |
| DD2 | 50,000 publishers, and none of them will call you. How do you stay fresh? | A cron job that polls them all | |
The same three habits answer all four:
Do not spend your questions on what a news site looks like. Spend them on where articles come from and what a read may cost.
Swipe to see all columns
| Scope Decisions | ||
|---|---|---|
| Question | Agreed answer | Why it matters |
| Where do articles come from? | From the publishers' own APIs, which we pull. No crawler. We never host the article text | A small data model: a title, a summary and a link |
| Push or pull? | Pull. We cannot make 50,000 publishers call us | Someone must decide when each one is pulled (DD2) |
| How fresh? | Big newsrooms within a few minutes, small sites within the hour | Publishers come in tiers, each with its own interval |
Out of scope (say this out loud): training the topic model, hosting article text, a general web crawler, likes, comments and shares, ads and billing, push notifications and email digests, and a second region.
FR1 — Pull and store. Pull every publisher's API on a schedule. Store each article's title, summary, link and publish time, once.
FR2 — Sort by topic. Put every article into one or more topics, such as tech or sports.
FR3 — Follow. A logged-in reader follows topics and publishers.
FR4 — Two feeds. A personal feed for a logged-in reader. A list of top stories for everyone, guests included.
FR5 — Click through. A click sends the reader to the publisher's page. The click also feeds ranking and trending.
The key principle behind all five
Swipe to see all columns
| Five facts and the conclusions they do not supportRead each row as: the fact on the left does not, by itself, imply the claim in the middle. | ||
|---|---|---|
| Fact | Does not imply | Why the gap exists |
| A topic has 2 million followers | A new article is written 2 million times | All of them want the same list. One shared list is enough |
NFR1 — Fast reads. 95% of feed reads answer within 200 ms, at 10,000 reads a second.
NFR2 — Fresh. A story from a big newsroom is in feeds within a few minutes. Top stories follow within minutes too.
NFR3 — Reads survive. When pulling, classifying or ranking fails, readers still get a feed.
NFR4 — Stored once, counted once. An article is stored once, however often it is pulled. A click is counted once, however often it is sent.
NFR5 — Consistent enough. Ranking may lag by seconds. A changed subscription shows within seconds.
| Capacity Thought Experiment | |
|---|---|
| Parameter | Value |
| Publishers | 50,000 in three tiers: 500 big newsrooms, 4,500 mid-size, 45,000 small sites |
| Pull interval | Every 2, 15 and 60 minutes: about 22 pulls a second in total |
| New articles | About 100 per publisher a day: 5 million a day, 58 a second |
| Readers | 10 million a month, 100,000 in the app at the same time |
| Feed reads | 10,000 a second at peak |
The number that identifies the real system is the gap between what comes in and what a copy per reader would cost:
in 58 articles a second
out 10,000 feed reads a second
copies 58 x 1,000,000 readers = 58,000,000 writes a second, if every reader got a copy
Few articles come in, many feeds go out, and every article is shared by about a million readers. So an article is written once, and the personal part happens on the read. Every number above is an illustrative assumption.
Interviewer signal: candidates who draw an inbox per user, as for a social network, have missed the number. Candidates who say "58 articles a second, each shared by a million readers, so I write each article once and build every feed on read from a few hundred candidates" have found the system.
Three ideas shape everything:
In a social network, a post goes to the few hundred followers of its author. Here an article goes to everyone who follows its topic: millions of readers who all want the same list of new articles. So the article is stored once and listed once per topic. What is personal, the choice and the order, is worked out when a reader asks.
The article table holds 450 million rows. A read never searches it. It takes the newest ids from a handful of short lists, about 300 in all, and ranks those. The cost of a read stays the same when the table doubles.
Ingest and read never call each other. The pull side stores an article and announces it with one event. The read side lives on lists that are built from those events. If pulling stops, readers get a slightly older feed. And everything in Redis is derived: it can be rebuilt from PostgreSQL and the event log.
The core recognition
This is fan-in, not fan-out. Fan-out copies one item to many readers. Fan-in lets many publishers flow into one shared store, and puts every feed together from shared lists at the moment it is read. Nothing is copied per reader.
| Design Decisions | |
|---|---|
| Design choice | Reason |
| A scheduler with tiers and an offset per publisher | Big newsrooms are pulled often, and 50,000 pulls never land on the same second |
| A conditional GET: the pull sends the feed's version tag, the etag | A publisher with nothing new answers in a few hundred bytes |
Five tables carry the design. The fields to explain are the unique rule on
article, thelast_seen_etagonpublisher, and theinterest_profileonuser.
One row per article. We keep what the feed shows. The text stays with the publisher.
Swipe to see all columns
| article | ||
|---|---|---|
| Field | Type | Comment |
id | STRING | Key, for example a-9001 |
publisher_id | STRING | Who published it, for example p-wire |
canonical_url | ||
One row per article and topic. Topics live in their own table, so articles can be classified again without touching article.
Swipe to see all columns
| article_topic | ||
|---|---|---|
| Field | Type | Comment |
article_id | STRING | For example a-9001 |
topic_id | STRING | For example tech |
score | ||
One row per publisher. It holds everything the scheduler needs.
Swipe to see all columns
| publisher | ||
|---|---|---|
| Field | Type | Comment |
id | STRING | Key, for example p-wire for Metro Wire |
tier | INT | 1, 2 or 3. Decides how often it is pulled |
ingest_url | ||
Swipe to see all columns
| user | ||
|---|---|---|
| Field | Type | Comment |
id | STRING | Key, for example u-maya |
locale | STRING | Language and country, for example en-US |
interest_profile | ||
Swipe to see all columns
| subscription | ||
|---|---|---|
| Field | Type | Comment |
user_id | STRING | The reader. Indexed, because every feed read starts here |
kind | ENUM | topic or publisher |
Swipe to see all columns
| Supporting records | ||
|---|---|---|
| Record | What it holds | Why it exists |
| Pull job | A publisher id and the stored etag | One pull that waits for a worker. Hidden for 60 s while a worker has it |
| Job log | One row per pull attempt: status, etag, time, error | A failing publisher can be found and explained |
article-created event | Article id, publisher, topics, publish time | |
Swipe to see all columns
| Storage | ||
|---|---|---|
| Store | Data | Consistency |
| PostgreSQL | article, article_topic, publisher, user, subscription, job log | The source of truth. Transactions, and the unique rule |
| Redis | Candidate sets, top stories, hot article cards | Derived. If it is lost, it is rebuilt from PostgreSQL and Kafka |
| Kafka | The streams article-created | |
Plain REST. A feed refreshes when the reader asks for it, so no push channel is needed.
Swipe to see all columns
| The public endpoints | ||
|---|---|---|
| Call | Who | What it does |
GET /v1/feed?cursor=&limit= | A logged-in reader | One page of the personal feed, and a next_cursor |
GET /v1/top-stories?locale=&cursor= | Anyone | The top-stories list. No login needed |
GET /v1/topics/{topic}/stories | ||
The cursor keeps page 2 honest. Trending reorders the list while Maya scrolls. So the first request keeps its ranked list of about 300 ids in Redis for 10 minutes, and the cursor points into that list. No article shows twice and none is skipped.
A click is a POST. Browsers prefetch links, and link checkers follow every GET. A GET that counts would count clicks that no person made. The POST carries the user, the article and the minute, and the same three values count once.
Present the design as four short stories, each in its own colour on one whiteboard: Phase 1 ingest (black), Phase 2 shelve (blue), Phase 3 read (green), Phase 4 click (purple). Phases 1 to 3 follow one article from its publisher into Maya's feed. The number on an arrow is the same number in the animation and in the step table.
Swipe to see all columns
| The four phases | |||
|---|---|---|---|
| Phase | Colour | Story | What it leaves behind |
| Phase 1: Ingest (FR1, FR2) | Black | A pull worker asks Metro Wire for news, gets a new article, has it classified and stores it | One article row, two topic rows, one event |
| Phase 2: Shelve (FR4) | Blue | The feed builder reads the event and puts the article on three shared lists | The article is on the lists that readers read |
How to read the picture
a-9001, "Chip maker opens new plant", published by Metro Wire at 09:00:05, with the topics tech and business. The reader is Maya, who follows tech, sports and Metro Wire.Each phase below is an interactive walkthrough of the same picture. It plays on its own. You can pause it, step with the arrow keys, and click any component to read its role.
Goal: get a new article into the store once, with its topics, soon after it is published.
pull p-wireScheduler → Pull queuep-wirenew rowSwipe to see all columns
| Phase 1 step by step (black arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | It is 09:00:14. Metro Wire is a tier-1 publisher: it is due every 2 minutes, 14 seconds past the even minute. The scheduler puts a job on the pull queue. | One pull job: p-wire, etag e41 |
| 2 | A pull worker takes the job and asks Metro Wire's API: anything new since version e41? The answer is 200 OK, the new version e42 and 2 new items. One of them is our article. | The job is hidden for 60 s |
| 3 | The worker looks up both items in the article store by canonical URL and publisher. Neither is there: both are new to us. | |
Why it is built this way
304 Not Modified and the pull ends at step 2.Because we cannot make 50,000 publishers build that, and the smallest never will. With pull, the pace, the retries and the load are ours to decide. If a big newsroom offers a push, use it to trigger a pull at once, and keep the schedule as the safety net.
Goal: put the article where readers will look, once, however many readers there are.
article-createdEvent log → Feed builderNothing is written in this step.
Swipe to see all columns
| Phase 2 step by step (blue arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | The feed builder reads the event article-created for a-9001 from the event log. | Nothing |
| 2 | It adds a-9001 to the lists of its two topics. The score is the publish time plus a 10-minute head start for a tier-1 publisher: 09:10:05. | a-9001 on feed:topic:tech and feed:topic:business |
Why it is built this way
feed:topic:tech is one list for 2 million followers. That is why three writes are enough.Following (FR3) needs no copies either. POST /v1/subscriptions writes Maya's subscription rows in PostgreSQL. Her next read simply takes other lists.
Because a read looks at the lists, not at PostgreSQL. Until the feed builder has handled the event, the article is stored and invisible. Normally that takes a second or two. If the builder falls behind, feeds go stale while every database looks healthy. So the time from event to list is measured and has an alarm.
Goal: answer within 200 ms, with the same amount of work for every reader.
/v1/feed?limit=20Reader's app → Feed serviceNothing is written in this step.
Swipe to see all columns
| Phase 3 step by step (green arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | It is 09:07. Maya opens the app, and it asks for the first 20 articles of her feed. | Nothing |
| 2 | The feed service reads Maya's user row and her subscriptions in one go: she follows tech, sports and Metro Wire, and her profile says tech 0.70, sports 0.30. About 5 ms. | Nothing |
| 3 | One round trip to Redis: the top 100 ids of her three lists and the top 50 top stories. 350 ids, about 300 without repeats. About 5 ms. | |
Why it is built this way
You can, but look at what it buys. The whole read is about 30 ms of server work. A cache of finished feeds holds an entry for each of 100,000 active readers, most of them never read twice, and it makes a breaking story up to five minutes late. Cache the parts that are shared, the lists and the cards. Compute the part that is personal.
Goal: send the reader to the publisher at once, and turn clicks into a top-stories list within a minute.
/v1/clicks/a-9001Reader's app → Feed serviceNothing is written in this step.
Swipe to see all columns
| Phase 4 step by step (purple arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | Maya taps a-9001. The app sends POST /v1/clicks/a-9001. | Nothing |
| 2 | The feed service looks up the article's canonical URL and answers with it. The app opens Metro Wire's page. | Nothing |
| 3 | The feed service puts one event on the | |
Why it is built this way
The profile learns from the same stream. A second consumer, the profile updater, nudges Maya's profile after her click: tech goes from 0.70 to 0.72 (DD4).
Because top stories should show what people read now. A total that only grows keeps last week's big story on top for ever. A window forgets: a click older than 15 minutes, or an hour, no longer counts. Short windows react fast and jump around, long ones are calm and slow. That is why the consumer keeps three.
The deep dives are the four questions from the top of the page. Each one compares three designs for the same scenario: a Bad one, which is usually the answer that sounds right; a Good one, which still leaves a gap; and a Great one, which holds. The answers start covered. Read the scenario, decide what you would build, then click each card.
Swipe to see all columns
| Deep Dive Map | |||
|---|---|---|---|
| Deep Dive | Topic | Scenario | NFR |
Scenario: Article a-9001 is tagged tech. Tech has 2,000,000 followers, and Maya is one of them. 5 million articles arrive every day. At peak, 10,000 feeds are read every second, each within 200 ms. How does a-9001 get into Maya's feed?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. Do what a social network does. When an article arrives, write its id into the mailbox of every reader who follows its topic. A read is then one lookup.
Where it breaks. A social post goes to a few hundred followers. a-9001 goes to 2,000,000. An average article reaches about a million readers, so 58 articles a second become 58 million writes a second. And nearly all are wasted: tech alone puts 200,000 articles a day into Maya's mailbox, and she looks at 60.
The idea. Store the article once. When Maya opens the app, ask the database for the newest articles of tech, sports and Metro Wire.
What it fixes. The writes. One row per article, no copies, and a new subscription works at once.
What it still misses. The reads. To rank, each read needs about 300 rows, so 10,000 reads a second pull 3 million rows a second out of a 450-million-row table, on the database that also takes the inserts. The slowest 5% leave the 200 ms budget. And the trending signal lives in the click stream, not in the table, so this feed can only sort by time.
The key idea. All followers of a topic want the same list of new articles. Write that list once and share it. Make it personal at the last moment, on a few hundred candidates.
How it works
feed:topic:tech as Maya. Only the ranking is his own.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure.
SELECT user_id FROM subscriptionFan-out worker → Article store2,000,000 readers, Maya is one of themNothing is written in this step.
Swipe to see all columns
| DD1 side by side | |||
|---|---|---|---|
| Bad: a mailbox per reader | Good: one table | Great: shared lists | |
| Writes for a-9001 | 2,000,000 | 3 rows | 3 rows and 3 list entries |
| Writes a second, all articles | About 58 million | About 170 | About 350 |
Check it against the scenario
| A tech article and 2 million followers | |
|---|---|
| Situation | Outcome with the Great option |
| a-9001 arrives | Three list entries. Nothing is written per reader |
| Maya follows a new topic | One subscription row. Her next read takes one more list |
| The feed builder is 5 minutes behind | Feeds are 5 minutes old. Nothing fails, and the lag alarm fires |
The trade-off to name. The lists are a second copy of what PostgreSQL knows, and a copy can lag: if the feed builder stops, articles are stored and nobody sees them. So the time from event to list has an alarm.
There, a post goes to the followers of its author, a few hundred for most accounts, and every reader follows different people. Each timeline is a different mix, so preparing it pays off. Here, a million readers follow the same topic and want the same list. A million copies of one list are pure waste.
"I would not fan out on write. An article here belongs to a topic with millions of followers, so a mailbox per reader means about 58 million writes a second. I store each article once and add its id to one sorted list per topic and one per publisher, in Redis. A feed read loads the reader's subscriptions and profile, takes the top hundred ids of each followed list plus the top stories, and ranks about 300 candidates in memory. That work is bounded: it does not depend on the size of the article table or on how popular a topic is."
Follow-up: "What if the lists are lost?" — They are derived. I rebuild them from the newest rows in PostgreSQL or from the article events. Meanwhile readers get top stories from the feed servers' memory.
Scenario: 50,000 publishers, and none of them will call us. Metro Wire, a tier-1 newsroom, publishes a-9001 at 09:00:05, and it should be in feeds within a few minutes. Valley Gazette, a small tier-3 site, publishes ten articles a day. How do we pull them all?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. A cron job starts a script. The script walks the list of publishers, pulls each feed, and stores what it finds.
Where it breaks. A pull takes about half a second, so one round over 50,000 publishers takes 7 hours. Metro Wire is number 31,000 on the list: its 09:00:05 story is picked up at about 13:18. And the loop is a chain. One publisher that hangs for 30 seconds makes everyone behind it wait.
The idea. Sort the publishers into three tiers: every 2, 15 and 60 minutes. A scheduler puts a job on a queue for every publisher that is due, and a pool of workers pulls them in parallel.
What it fixes. Freshness, and the chain. Metro Wire is pulled at 09:02:00, when a-9001 is two minutes old. A slow publisher blocks one worker.
What it still misses. Three things. At 10:00:00 all three tiers are due: 50,000 jobs in the same second. Every pull downloads the whole feed again: 1.9 million pulls a day times 50 items is 94 million items to check for 5 million new ones. And a publisher that answers 503 is retried at once, round after round. Nobody notices that its feed is dead.
The key idea. Spread the pulls evenly over the clock, and let a publisher with nothing new say so in one short answer.
How it works
If-None-Match: "e41". At 09:00:14 the answer is 200 OK with etag e42 and 2 new items. Only those two go on.304 Not Modified: a few hundred bytes, and nothing to do.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure.
for each publisher: pullScheduler (one cron job) → every publisherNothing is written in this step.
Swipe to see all columns
| DD2 side by side | |||
|---|---|---|---|
| Bad: one loop | Good: tiers on the clock | Great: tiers with an offset | |
| Metro Wire's story is picked up after | Up to 7 hours | At most 2 minutes | At most 2 minutes |
| The busiest second | One pull at a time | 50,000 jobs at 10:00:00 | About 22 pulls |
Check it against the scenario
| 50,000 publishers and one fresh story | |
|---|---|
| Situation | Outcome with the Great option |
| 10:00:00, every tier is due | Each publisher fires at its own offset: about 22 pulls in that second |
| Valley Gazette answers 503 | Tried again after 1, 2, 4 and 8 minutes. Then the dead-letter queue, and a row in the job log |
| A worker dies in the middle of a pull | The job comes back after 60 s. The etag was not saved, so the same items arrive again, and the unique rule stores them once |
The trade-off to name. Pulling has a floor: a tier-1 story can be 2 minutes old before we even ask. A shorter interval means more calls, most of them answered with 304. And some publishers send no etag. Then the worker falls back to If-Modified-Since, or downloads the feed and lets the unique rule sort it out.
A random wait changes the gap between two pulls of the same publisher: with a 2-minute interval, 10 seconds one time and almost 4 minutes the next. The hash gives a publisher the same offset every round. Each publisher is pulled at an even pace, and the 50,000 offsets are spread evenly over the clock.
"Ingestion is pull, because I cannot make 50,000 publishers push. A scheduler keeps a tier per publisher, say 2, 15 and 60 minutes, and puts a job on a queue when one is due. Each publisher has a fixed offset from the hash of its id, so the pulls spread evenly, about 22 a second, with no spike on the full hour. Workers send a conditional GET with the stored etag, so an unchanged feed costs a 304. New items pass a unique index on canonical URL and publisher, are classified, and are stored in one transaction with the new etag. Failures back off and end in a dead-letter queue."
Follow-up: "A big publisher offers a webhook. Do you take it?" — Yes, as a trigger for an immediate pull. The schedule stays, so a missed webhook costs two minutes, not an article.
Scenario: It is 09:15. Sports Daily broke a transfer story, a-7001, at 09:00. In the last 15 minutes it got 60,000 of all 200,000 clicks, and six more Sports Daily stories got 5,000 each. One publisher has 45% of all clicks. Metro Wire's a-9001 has 12,000. The 20th story on the list has 3,000. What should top stories show?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. Count the clicks per article. Every minute, sort by count and write the list.
Where it breaks. a-7001 is first with 60,000 clicks, and that is right: it is the story of the hour. But its six siblings have 5,000 each, more than the 3,000 of the 20th story. So 7 of the 20 top stories come from one publisher. A guest who opens top stories sees a sports page.
The idea. Also count the clicks per publisher. A publisher with more than 40% of the last minute's clicks is taken off the list.
What it fixes. The flood. While the rule applies, Sports Daily's ride-along stories are gone.
What it still misses. Two things. The rule removes a-7001 as well, and hides the most-read story of the hour. And one minute is a nervous measure. At 09:14 Sports Daily has 43% and all seven stories vanish. At 09:15 it has 38% and they are back. At 09:16 it has 41% and they are gone again.
The key idea. Brake, do not ban. The more of the clicks one publisher holds over a longer time, the less each of its stories counts. A story that is big enough still wins.
How it works
The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure.
clicksEvent log → Trending consumer09:15updateSwipe to see all columns
| DD3 side by side | |||
|---|---|---|---|
| Bad: raw counts | Good: a hard limit | Great: a smooth factor | |
| What is measured | Clicks per article | Each publisher's share of the last minute | Each publisher's share of the last 15 minutes |
| Sports Daily stories in the top 20 | 7 | 7 or none, changing every minute | 1: the real story |
Check it against the scenario
| 45% of all clicks for one publisher | |
|---|---|
| Situation | Outcome with the Great option |
| Sports Daily holds 45% over 15 minutes | Factor 0.3. a-7001 stays first with 18,000. Its six siblings fall to 1,500 and leave the top 20 |
| a-9001, 12,000 clicks | Metro Wire's share is small, so its factor is 1.0. Second place |
| One minute at 38%, the next at 43% | Nothing happens. The 15-minute share hardly moves |
The trade-off to name. The factor is a judgement: 20%, 40% and 0.3 are tuned on real days. A 15-minute window is slow on purpose, so a publisher that floods the list is braked a few minutes late. And exact counters for every article do not fit on one machine for ever: each partition keeps approximate counts and its own top list, and a merge step combines them. The Top-K Videos page walks through that counting.
A cap is simple, and many products use one as an extra rule. On its own it has two problems. It is a cliff: the third story is out however strong it is, and the second is in however weak. And it does not ask how dominant the publisher really is. The factor keeps one rule for everyone: a story stays if it still wins after the brake.
"Clicks go to a stream partitioned by publisher. A consumer keeps rolling counts per article and per publisher over 1 minute, 15 minutes and an hour, and rewrites top stories every minute. To stop one publisher from owning the list, I multiply each story by a factor that depends on its publisher's share of all clicks over 15 minutes: 1.0 up to 20%, falling in a straight line to 0.3 at 40%. It is continuous, so nothing jumps, and the longer window keeps stories from flipping in and out. A truly big story still wins after the factor. Its ride-along stories do not."
Follow-up: "How do you count clicks for millions of articles?" — Per partition, with a count-min sketch and a small heap, then a merge across partitions. Only the head of the list has to be right.
Scenario: Every feed read needs two things about Maya: her subscriptions, and her interest profile, tech 0.70 and sports 0.30, about 4 kB in full. There are 10 million users and 10,000 reads a second, each within 200 ms. At 09:07 she clicks a tech story, and her profile should move to tech 0.72. Where does the profile live?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. A profile is a list of numbers, and lists of numbers go into a vector database.
Where it breaks. A vector database answers one question well: which vectors are closest to this one? Nobody asks that here. Every call is "the profile of u-maya", a lookup by key. For that, the feed read pays a second network hop, a click must update a second system, and when the vector store is down nobody gets a personal feed.
The idea. Keep the profile in Redis, under profile:u-maya. A read takes less than a millisecond, and a click changes one field.
What it fixes. The speed and the shape. A key-value store is the right tool for a lookup by key.
What it still misses. Durability. When Redis restarts, the profiles are gone unless a second, durable copy exists. Two copies need a rule for which one is right, and a path to refill the other. That is a lot of machinery for 4 kB that is always read together with a row we load anyway.
The key idea. The profile is small, and it is always read together with the subscriptions. Put it where that read already goes.
How it works
interest_profile in it, and the subscriptions. About 5 ms, no second hop.clicks stream, like every click.UPDATE on Maya's row: tech 0.70 becomes 0.72.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure.
/v1/feedReader's app → Feed serviceSELECT subscriptionsFeed service → Article storetech, sports, Metro WireNothing is written in this step.
Swipe to see all columns
| DD4 side by side | |||
|---|---|---|---|
| Bad: a vector database | Good: a Redis hash | Great: a column on the user row | |
| Hops for one feed read | 2: PostgreSQL and the vector store | 2: PostgreSQL and Redis | 1: PostgreSQL |
| Is the profile durable? | Yes, in a second system | Not by itself | Yes, with the user row |
Check it against the scenario
| 4 kB per reader, on every read | |
|---|---|
| Situation | Outcome with the Great option |
| The database fails over | The profile comes back with the user row. There is nothing to rebuild |
| The profile updater is down for an hour | Profiles are an hour old. Feeds still work, and the clicks wait in the stream |
| Profiles grow to 50 kB each | Time to move them out: a fat column slows every read of the user row |
The trade-off to name. Every click becomes a database write. At 1,000 a second that is fine, and grouping a reader's clicks per minute cuts it further. The answer changes with the facts: a profile of tens of kB, or a job that reads profiles without the user row, is the sign to give the profile its own store. The lesson is not "never add a cache". It is "count the bytes and the reads first".
When the question is about closeness. Suppose every article and every reader is turned into a list of a few hundred numbers, and the feed asks "which 500 of 450 million articles are closest to Maya?". That is a search by similarity, and it is exactly what a vector database is built for. Fetching one reader's profile by her id is not that question.
"The interest profile is a few kilobytes of topic weights per user, and the feed read always needs it together with the subscriptions. So it is a JSON column on the user row, and one query loads both. Updates come from the click stream, about a thousand a second at peak, which PostgreSQL handles. A vector database solves nearest-neighbour search, which I do not need. A Redis hash is faster to read, but then I own a second copy and its failure cases. I would revisit this when a profile reaches tens of kilobytes or another system needs profiles on their own."
Follow-up: "And at 500 million users?" — The user table is sharded by user id, and the profile travels with its row. Still one lookup on one shard.
Some interviewers point at the ranker and ask: how would you learn this? Two models sit in this design: the ranker, a hand-written formula today, and the topic classifier, a black box so far.
| The ML side in one table | |
|---|---|
| Question | A good short answer |
| What does the model predict? | For this reader and this article, now: the chance of a click that turns into a real read, say 30 seconds or more. The topic classifier predicts which topics an article belongs to, several at once |
| Where do the labels come from? | The feed logs what it showed, the click stream what was opened. Shown and read is a positive, shown and passed over a negative. For the classifier: articles labelled by editors, and the section the publisher filed them under |
| Which features matter? | The reader: interest profile, subscriptions, language, hour of day. The article: topics, publisher tier, age, clicks in the last 15 minutes. The pair: Maya's affinity for this article's topic and publisher |
| Which model, simple first? | Today's weighted sum. Next, a logistic regression on the same features, so the weights are learned. Then gradient-boosted trees. Only about 300 candidates reach the model, so a small one is enough |
Position bias. The first card is clicked because it is first: say 12% of the time in position 1 and 2% in position 10. A model trained on raw clicks learns that whatever was on top is good, and keeps it there. Log the position of every card. Use it as a feature in training and set it to one fixed value when serving, or shuffle a small share of pages.
Cold start and the closed loop. Valley Gazette has no clicks, so it is never shown, so it never gets clicks. Give 1 slot in 20 to articles the model knows little about. A new reader gets top stories with a mix of topics until they have clicked about ten times.
Clickbait. A model that is paid in clicks learns to love misleading headlines. Pay it in real reads. A reader who is back within 5 seconds counts against the article.
The topic threshold. a-9001 scored tech 0.92 and business 0.61, and both pass the line of 0.5. Lower the line and articles land on lists where they do not belong. Raise it and some articles land on no list at all.
The logs only contain articles that the old ranker chose to show. The new model's favourites were rarely shown, so the replay has almost no clicks to judge them by. Trust the A/B test, and keep a small random slice of traffic so that future logs are not shaped by the ranker.
| If the interviewer keeps going | |
|---|---|
| Question | Short answer |
| The same agency story appears under 100 publishers' links | The unique rule only catches the same link from the same publisher. Compute a SimHash, a fingerprint that is almost the same for almost the same text, over the title and the first paragraph. Group near-copies and show the version of the highest-tier publisher |
| The topic classifier is down | Keep pulling. Store articles as pending and leave them off the topic lists. When the classifier is back, classify them and shelve them |
| The ranker fails | Order the candidates by time. The feed is less personal and still correct |
| Redis is lost | Every feed server keeps the last top-stories list in memory and serves that. The lists are rebuilt from the newest rows in PostgreSQL and from the event log |
An article is not a post for a few hundred followers. A mailbox per reader costs 58 million writes a second.
10,000 reads a second on a 450-million-row table miss the 200 ms. A read takes about 300 ids from short shared lists.
One loop over 50,000 publishers takes 7 hours and stops at the first slow one. Use tiers, a queue and a pool of workers.
Every tier is due at 10:00:00, and 50,000 jobs land on one second. Give each publisher its own fixed offset.
Most pulls find nothing new. Send the stored etag and accept a 304.
Browsers prefetch and link checkers follow links, so the counter fills with clicks nobody made. Use a POST that counts once per user, article and minute.
A cut-off on the last minute hides the real story and flips the list. Use a smooth factor over 15 minutes.
A vector database or a second cache for the interest profile adds a hop and a second copy. A column on the user row is read in the query you run anyway.
The shape of a strong answer: say out loud that an article is shared and a feed is personal. Pull every publisher on its own schedule, and ask before you download. Store each article once and list it once per topic. Build a feed from about 300 candidates when it is read. Brake a dominant publisher with a smooth factor, and keep the reader's interests next to the reader.
Write once, personalise on read
58 articles a second come in, and each is shared by about a million readers. Three list entries per article and 300 candidates per read replace 58 million writes a second.
Pull on your own terms
Three tiers, a fixed offset per publisher and a conditional GET: about 22 pulls a second, no spike on the full hour, and a 304 when nothing is new.
Prefer the smooth and the simple
A factor that falls in a straight line over a 15-minute share, not a cut-off on the last minute. A column on the user row, not a new database for 4 kB.
| What the interviewer expects at each level | |
|---|---|
| Level | A strong answer shows |
| Junior | The data model: articles, publishers, users, subscriptions. Pulling on a schedule, a database, and a cache for a feed that is mostly read |
| Mid-level | Rejects a copy per reader with the reason: an article is shared by overlapping readers. Splits ingest from read and names the event that joins them. Sorted lists in Redis as candidates, tiers and the conditional GET, a stream for clicks |
| Senior | Explains why a cron job fails at 50,000 publishers: offsets, a dead-letter queue. Defines the cursor and why a click is a POST. Brakes a dominant publisher without flipping the list, and argues for the profile on the user row with the point at which that changes |
These aren't toy problems — they reflect real infrastructure challenges at companies that serve feeds to millions of readers. If you want to walk through this design in a mock interview or get feedback on your own approach, book a session with us. We're here to help you sharpen your thinking, build your confidence, and land your next offer.
Pick an answer for each question, and you see at once whether it is right. Show explanation opens the answer, why it is right, and why each of the other options fails.
Question 1 of 10
5 million articles arrive a day, and an average article is followed by about 1 million readers. How many writes a day does a mailbox per reader need?
Question 2 of 10
Article a-9001 has the topics tech and business and comes from Metro Wire. With shared lists, how many list entries does it cost?
Question 3 of 10
The article table grows from 450 million to 900 million rows. What happens to the work of one feed read?
Question 4 of 10
A pull worker sends Metro Wire's stored etag, and the publisher answers 304 Not Modified. What does the worker do next?
Question 5 of 10
Why does every publisher get its own fixed offset inside its pull interval?
Question 6 of 10
A pull job is handed out twice, and two workers try to store a-9001 at almost the same moment. What stops a duplicate?
Question 7 of 10
Why is a click recorded with a POST, and not with a GET link that counts?
Question 8 of 10
A publisher holds 30% of all clicks over the last 15 minutes. The factor is 1.0 up to 20% and falls in a straight line to 0.3 at 40%. What is its factor?
Question 9 of 10
Why does the factor use a publisher's share over 15 minutes, and not over the last minute?
Question 10 of 10
The ranker is retrained on raw click logs. Articles shown in first place got the most clicks. What goes wrong?
| One loop takes 7 hours, and on the full hour 50,000 jobs fire at once. Tiers, an offset per publisher, and "anything new?" |
| DD3 | One publisher's story goes viral and its other stories fill top stories. What now? | Remove a publisher that passes a limit | A hard limit hides the real story and flips every minute. Use a smooth factor over a longer window |
| DD4 | The ranker needs every reader's interests. Where do you keep them? | In a vector database, or at least in a cache | It is 4 kB, read by user id, always together with the subscriptions: a column on the user row |
| Is a feed prepared for every reader in advance? | No. A feed is put together when it is read | A popular topic has millions of followers. A copy per reader does not scale (DD1) |
| How many reads? | 10,000 a second at peak, 95% of them under 200 ms | A read may touch a few hundred ids, never the whole article table |
| One story dominates top stories? | It may lead. Its publisher may not take the whole list | Trending needs a brake (DD3) |
| Ingestion or ranking is down? | Readers still get a feed, a little older or less personal | The read side must not depend on the write side |
| We pulled the publisher | There is something new | Most pulls of a busy schedule find nothing. The publisher can say so in a few hundred bytes |
| The article is stored | Readers can see it | Readers look at lists, not at the table. The article must reach the lists first |
| A story has the most clicks this minute | It belongs on top | One publisher can own a minute. A list built on one minute flips every minute |
| A request reached the click link | A person clicked | Browsers prefetch links, and link checkers follow them |
| Read budget |
| 200 ms for 95% of reads. The server work fits in about 30 ms |
| Hot articles | 90 days: 450 million rows of about 1 kB, 450 GB |
| Followers per article | About 1 million on average. The topic tech has 2 million |
| A copy per reader | 5 million articles times 1 million readers: 5 x 10^12 writes a day |
| Interest profiles | About 4 kB per reader: 40 GB |
| Clicks | A few hundred a second, about 1,000 at peak |
| A unique rule on canonical URL and publisher | Pulling the same article twice stores it once |
| One event per new article | The only link between the write side and the read side |
| Shared lists per topic and per publisher in Redis | Three writes per article, however many readers follow the topic |
| About 300 candidates and a small formula | A read costs the same on day 1 and on day 900 |
| Clicks as POST, into a stream keyed by publisher | No clicks from prefetching, and each publisher's clicks are counted in one place |
| A smooth factor over 15 minutes for trending | One publisher cannot take over top stories, and the list does not flip |
| The interest profile as a column on the user row | One read returns everything the ranker needs to know about the reader |
STRING |
The article's one official link. Unique together with publisher_id |
title, summary | STRING | What a feed card shows |
language | STRING | For example en |
published_at | TIMESTAMP | When the publisher released it |
status | ENUM | ready, or pending while it waits for the classifier |
FLOAT |
| How sure the classifier is, for example 0.92 |
STRING |
| Where its feed is |
last_seen_etag | STRING | The version tag of the feed as we last saw it, for example e41 (DD2) |
last_fetched_at | TIMESTAMP | When we pulled it last |
JSON |
| How much the reader cares about each topic, for example tech 0.70 and sports 0.30. About 4 kB (DD4) |
target_id | STRING | For example tech, or p-wire |
| Tells the read side that a new article exists |
clicks event | User, article, publisher, minute | One click. Keyed by publisher, counted once per user, article and minute |
| Candidate set | feed:topic:tech: the newest 1,000 article ids of a topic, newest first | A shared list. Every follower of the topic reads the same one |
| Top stories | topstories:global: the 100 most-clicked articles right now | Rewritten every minute |
clicksKept for days, so a consumer can read them again. clicks is partitioned by publisher |
| SQS | Pull jobs | At least once. A job that is not finished comes back |
| Anyone |
| The newest articles of one topic |
GET /v1/publishers/{id}/stories | Anyone | The newest articles of one publisher |
POST /v1/subscriptions | A logged-in reader | Follow topics and publishers. Sending only topics leaves the publishers as they are |
DELETE /v1/subscriptions | A logged-in reader | Unfollow, with the same body |
POST /v1/clicks/{article_id} | Anyone | Returns redirect_url and records the click |
| Phase 3: Read (FR3, FR4) |
| Green |
| Maya opens the app. The feed service collects 300 candidates, ranks them and returns 20 |
| Nothing durable. A feed is computed, not stored |
| Phase 4: Click (FR4, FR5) | Purple | Maya taps the article. She lands on Metro Wire's page, and the click moves top stories | One click event and a fresh top-stories list |
| Nothing |
| 4 | The worker sends the title and summary to the topic classifier. Within 200 ms it answers: tech 0.92, business 0.61. | Nothing |
| 5 | The worker stores the article in one transaction, together with its two topics and the publisher's new etag. | article a-9001. article_topic tech and business. publisher p-wire: etag e42 |
| 6 | The worker announces the article on the event log and deletes its job. | Event article-created for a-9001. The job is gone |
| 3 | It adds a-9001 to the list of its publisher. | a-9001 on feed:publisher:p-wire |
| 4 | It cuts each of the three lists to its newest 1,000 ids. | The oldest ids fall off |
| 5 | It commits its position in the stream. | The position moves on |
| Nothing |
| 4 | The feed service scores the 300 candidates in memory. a-9001 gets 0.80. The best 20 stay. About 5 ms. | Nothing |
| 5 | One batched lookup fills in the 20 cards: title, summary, publisher, link. Hot cards come from a cache. About 10 ms. | Nothing |
| 6 | The app gets 20 articles and a cursor for the next page. About 30 ms on the server. | The ranked list is kept in Redis for 10 minutes, for page 2 |
clicks| One click event |
| 4 | The trending consumer reads the event. It counts once per user, article and minute: one more click for a-9001 and for Metro Wire, in its 1-minute, 15-minute and 1-hour windows. | The click counters |
| 5 | Every minute the consumer works out the list again: clicks in the window, times a factor for the publisher (DD3). It writes the best 100. | topstories:global is replaced |
| 6 | A guest opens top stories. The feed service reads the first 20 ids of topstories:global and fills in the cards. | Nothing |
| DD1 |
| A million readers, one article |
| A tech article, 2 million followers, 10,000 reads a second |
| NFR1 — Fast reads |
| DD2 | Pulling 50,000 publishers | One story at 09:00:05, and the full hour at 10:00:00 | NFR2, NFR4 — Fresh, stored once |
| DD3 | One publisher takes over top stories | 45% of all clicks go to one publisher | NFR3 — A feed worth reading |
| DD4 | Where the interest profile lives | 4 kB per reader, needed on every read | NFR1 — Fast reads |
| One lookup |
| About 300 rows from a 450-million-row table |
| About 300 ids from short lists |
| Ranking | Fixed when written | By time only | By freshness, interests, publisher and trending |
| A publisher with nothing new |
| The whole feed, again |
| The whole feed, again |
| 304, a few hundred bytes |
| A publisher that keeps failing | Blocks the loop | Retried for ever | Backs off, then the dead-letter queue |
| a-7001, the story of the hour |
| First |
| Hidden half of the time |
| First |
| When the share falls again | Nothing changes | Everything jumps back at once | The factor climbs slowly: 0.65 at 30% |
| Copies to keep in step |
| 2 systems |
| 2 copies |
| 1 |
| New things to run | A vector database | A cache and its refill path | Nothing |
| The offline metric | Replay a day of logged feeds and score the order the model would have chosen. NDCG at 20 rewards putting the articles that were read near the top |
| The online metric | An A/B test: click-through rate, real reads per session, and readers who come back the next day. Guard rails: response time, and how many publishers appear on a page |
| Serving inside 200 ms | The features are at hand: the profile comes with the user row, the article numbers with the candidates. Scoring 300 rows takes about 5 ms. If the model fails, today's formula takes over |
| Rollout and monitoring | Shadow first: score, log, show nothing. Then 1% of readers, then more. Watch click-through, real reads, and each publisher's share of clicks |
| A worker dies between the insert and the event | The article is stored and never shelved. Write an outbox row in the same transaction and let a small relay publish it, so the event cannot be lost |
| What do you monitor? | The pull lag per tier, the time from event to list, and the share of duplicates per publisher. A sudden rise in duplicates means a feed is repeating itself |
| Other languages and countries | One top-stories list per locale, topstories:locale:en-US, counted from that locale's clicks by the same consumer |
| What may we show of an article? | The title and the summary. The first paragraph is kept only for classification, never shown, and deleted after a while |