LESSON 06 · Ranking decision

Separate candidates from order

Start with recency, then add ranking without making the source of truth depend on a score.

SYSTEM VIEW

The feed path

Diagram view
Scoring—
Page 2 repeats—
Snapshot—

Watch a ranked feed score 500 candidates, then hold its order steady from page one to page two.

  1. A chronological feed is easy to reason about: the Feed service gathers candidates from the Inboxes, the Access check keeps the allowed ones, and the page sorts them newest first. Decide early between this and ranking, because storage and paging differ.

    Order
    time, then post ID
    Instagram
    ranked since 2016
    Mastodon
    chronological

    What changed

    • Candidates from the Inboxes
    • Allowed posts only
    • Newest first
  2. A ranked feed adds a Ranker after the Access check. It scores a bounded set of 500 allowed candidates on relationship, freshness and past interactions. At an example 0.1 ms a post, that uses 50 ms of the page’s latency budget.

    Per post
    0.1 ms
    500 candidates
    50 ms
    Score
    derived, can change

    What changed

    • Ranker
    • 500 allowed candidates scored
    • 50 ms of latency
  3. The Access check runs before the Ranker. Of 501 candidates, one is a private post the Reader may not see: the check holds it, and only 500 reach the Ranker. Ranking also needs diversity, quality and abuse controls, so engagement can’t amplify spam.

    Candidates
    501
    Held
    1 private post
    Scored
    500

    What changed

    • Access check before the Ranker
    • 1 private post held
    • Diversity and abuse controls
  4. Suppose page two rescores every candidate. With pages of 20, post 5007 falls from #20 to #21 between requests, and post 5033 rises from #21 to #20. Page two opens with 5007 again, and 5033, now on page one, is never seen.

    Post 5007
    #20 → #21
    Post 5033
    #21 → #20

    What changed

    • Scores recomputed for page 2
    • 5007 shown twice
    • 5033 never seen
  5. The Feed service pins a session: it stores 500 ranked IDs in Feed sessions. Page two reads ranks 21–40 from that snapshot instead of rescoring, so nothing repeats. At 8 bytes an ID, that is about 4 KB a session, 4 GB for a million.

    Per session
    500 × 8 B = 4 KB
    1M sessions
    4 GB

    What changed

    • Inboxes
    • Feed sessions
    • 500 ranked IDs stored
    • Page two: ranks 21–40
  6. Ranked paging needs an ordering contract across pages. Try each: Snapshot reads the IDs ranked 21–40 from 4 KB of session memory; Token keeps the order in an opaque token and stores nothing; Rescore shows 5007 again. Measure relevance and freshness, not only click rate.

    Measure
    relevance + freshness
    Not only
    click rate

    What changed

    • Snapshot: 4 KB a session
    • Token: nothing stored
    • Rescore: 5007 repeats
    Page two from

Space plays · ← → step · Home resets

THE IDEA

How it works

Chronological ordering makes the first version easy to reason about: newest eligible posts appear first. A ranked feed changes the product goal. The candidate stage still gathers allowed posts, but a ranking stage scores a bounded set using signals such as relationship strength, freshness, and prior interactions. The score is a derived value and may change as behavior changes. If scoring takes an example 0.1 ms per post, 500 candidates use 50 ms of the page’s latency budget.

Do not rank before access checks: a high score cannot make a private post visible. A ranking system also needs diversity, quality, and abuse controls; otherwise engagement signals can amplify spam. Decide early whether you are building a chronological feed or a ranked one, because the storage and pagination choices differ. Both are defensible: Instagram moved to a ranked feed in 2016, while Mastodon’s home timeline stays chronological.

For ranked pagination, pin a feed session, snapshot the candidate set, or carry an opaque continuation token that captures enough ordering state. Recomputing all scores between pages can reorder items: a post that falls from page one to page two appears twice, and one that rises onto page one is never seen. A snapshot costs memory, about 4 KB for 500 IDs at 8 bytes each, or 4 GB for a million open sessions. Measure both relevance and freshness, not only click rate.

DECISION POINT

A product switches from newest-first to “most relevant.” Why might the old timestamp cursor produce repeated posts?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • Candidate selection, authorization, and ranking are distinct stages.
  • Ranked pagination needs an ordering contract across successive pages.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
RecallQUESTION 01

What does the ranking stage operate on?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.