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.

How to approach it

What this question tests, where it gets hard, and how to spend the time.

Read the question

What this problem tests

  • Can you place the work?

    Write time or read time. Interviewers want two numbers compared, not a slogan.

  • Do you see the uneven part?

    The average has 500 followers. A few have 100 million. One design cannot serve both.

  • Do you count the hidden reads?

    Twenty posts on a page means twenty lookups. That is larger than the feed traffic.

  • Do you protect people?

    Blocks, deletions and audience changes must beat every cached copy.

Think

Five questions before you draw

Ask yourselfHere
Who does what?A person posts; hundreds of others open their feeds later, at different times
What must never go wrong?Showing a post to someone who may not see it; an empty feed
What is the hardest thing?Fan-out when follower counts differ by a factor of a million
What breaks first as it grows?Gathering from 500 accounts on each read, then big accounts, then post lookups
What am I giving up?Freshness by seconds, and storage for ready feeds, in return for fast reads

Who should do the work?

Warm means the owner opened the app in the last seven days. Cold feeds are rebuilt when they return.

Time

Spend the 45 minutes

MinutesDoLeave withSkip
0 to 5Clarify, choose three features, set targetsPost, read feed, new-post hintAds, messaging, groups in detail
5 to 10Only sums that decidePush against pull, feed cache sizeVideo storage, unless asked
10 to 15Endpoints and main recordsCreate post, read feed with a cursorProfile fields
15 to 25Version 1, then grow itA read and a write, end to endModel architecture
25 to 40Two deep dives: fan-out, then ranking or privacyA decision with a cost for eachTraining pipelines
40 to 45Failures, what next, recapA clear last sentenceNew features

Lines you can open with

  1. 1

    Start

    "I will agree scope and scale, get a simple feed working, then spend our time on fan-out and the read path. Is that what you would like?"

  2. 2

    Park something

    "Ranking can fill an interview by itself. I will treat it as a function with a time limit and come back."

  3. 3

    When stuck

    "Let me look at my two products again. Which one is too large now?"

  4. 4

    Close

    "Normal posts are pushed, big accounts pulled, permission is checked at read. The part I would test first is a lost feed cache."

Patterns inside this problem

PatternThe signalWhere it lands
Precompute for reads50 reads for each writeReady feeds in Redis
Uneven loadFollower counts differ a million timesHybrid push and pull
Fan-out through a queueOne event, many slow effectsKafka and workers
Hot keyEveryone reads the same postIn-process copy, sharded counters
Graceful fallbackA clever part may failNewest first when ranking is down

Do

  • Compare push and pull with numbers
  • Name the big account problem before you are asked
  • Filter at read time
  • Say what users see when a part fails

Traps

  • Push for everyone
  • Fan out before answering the author
  • Trusting the cache for privacy
  • Strict consistency for a feed
  • One database at two billion users
  • No rate limits