Chapter 1 · Part 1

Your feed is a ranking

Open TikTok, YouTube, Instagram or Spotify and something quietly remarkable happens: out of hundreds of millions of possible posts, songs and videos, the app picks a tiny handful to show you — and somehow they're often exactly what you wanted. That feeling of being known isn't magic or eavesdropping. It's a ranking problem, and this whole course is about how it's solved.

Here's the entire shape of it, before any details. For every candidate item, the system predicts a single number — how likely are you to engage with this? — then sorts by that number and shows you the top few. That's a recommender system.

Scroll to watch a pile of candidates get scored and ranked into a feed.

Step 1: every candidate post gets a predicted engagement score.

scroll

Score, then sort

Almost every feed you use is built from the same three steps:

  1. Candidate generation — narrow billions of items down to a few thousand plausible ones (recent, from people you follow, in topics you like).
  2. Scoring — predict an engagement score for each candidate: the chance you'll click, watch, like, or linger.
  3. Ranking — sort by score and show the top handful, sometimes re-shuffled for variety.

Why "engagement" is the catch

Notice what the score predicts: engagement, not value. The system optimizes for what keeps you tapping — which is usually helpful (you really do like cooking videos) but sometimes not (outrage and cliffhangers are engaging too). Hold onto that distinction; it's the seed of the filter-bubble problem we'll reach in the final chapter.

feed.py — the universal feed, in five lines
candidates = generate_candidates(user)        # a few thousand plausible items

scored = [(item, score(user, item)) for item in candidates]

feed = sorted(scored, key=lambda x: x[1], reverse=True)[:k]
return [item for item, _ in feed]

Where we're headed

The one piece we've hand-waved is score(you, item) — the predicted engagement. Building it well is the whole field of recommender systems. And it starts with a question: how does the app know anything about you in the first place? You never filled out a taste survey. Next: the signals you give off without noticing.