AlgoViz

Design a news feed like Facebook's

hard 50 min

Show each person the best recent posts from everyone they follow, in a fifth of a second.

Explain your choices

Answer first. Then compare your reasoning.

13 questions 0 got it 0 to review13 not marked

Summary

Trade-offs and cheat sheet

Decisions

DecisionChoiceBecauseCost
Push or pullBoth, by followers2.3M against 116M, and uneven authorsTwo paths
Feed entryID and timeOne copy of each postHydration reads
OrderRanked once a visitStable pagesSession storage
Write pathDurable, then queueThe author does not waitSeconds of delay
Follow dataTwo partitioned tablesOne-step questionsEvery edge written twice
ConsistencyEventual, own posts at onceNobody compares feedsCounts are old
PrivacyChecked at readCopies lieWork on each read
UpdatesSmall hints on a stream16.7M polls savedOpen connections

When they push back

They sayAnswer with
"Why 10,000?""It is where one post costs a worker about a second. I would measure delivery delay and move it."
"Use a graph database.""The feed asks one-step questions, which two key lookups answer. I would add one for friend suggestions."
"Just cache the whole feed reply.""Then a deletion or block stays visible. I cache IDs and posts separately and check on read."
"Can't users see posts instantly?""Yes, for a price: no batching, and hints to 500 million streams. Ten seconds costs far less. Which would the product choose?"
"Isn't 25 TB of memory expensive?""Yes. Options: keep 200 IDs, keep only 3 days active, or pull for rarely seen users. Each lowers cost and raises rebuilds."