Sub topic 3
Narrowing Millions of Posts to a Candidate Pool
Prerequisites: you should understand that a feed can be chronological or ranked, and that a platform can estimate probabilities such as the chance you will like a post. You should also be able to read short Python code.
A large platform may have millions of posts available when you open the app. Ranking every post for every user would be slow and expensive. The platform first creates a candidate pool: a much smaller set of posts that might be worth showing you. A later ranker scores and orders those candidates.
Sources of candidates
Candidate generation usually combines several retrieval methods. Retrieval means finding items that match a rule or query.
Common sources include:
- Posts from accounts you follow.
- Recent posts from accounts with which you often interact.
- Posts similar to content you viewed, liked, or saved.
- Posts popular among people with similar interests.
- Recommended accounts or topics.
- Promoted posts selected by an advertising system.
- Posts that are locally or globally popular.
Each source catches different opportunities. A following-based source keeps the feed connected to the user's chosen network. A recommendation source helps the user discover unfamiliar content. A popularity source can provide broad-interest posts.
The system often takes the union of these results. If one post appears through several sources, the system removes the duplicate but can keep metadata about its sources. That metadata can become a ranking signal later.
from dataclasses import dataclass
@dataclass(frozen=True)
class Post:
post_id: str
author: str
source: str
def build_candidates(*retrieval_lists, limit=10):
"""Merge retrieval results, remove duplicates, and keep source labels."""
candidates = {}
for posts in retrieval_lists:
for post in posts:
if post.post_id not in candidates:
candidates[post.post_id] = {
"post": post,
"sources": set(),
}
candidates[post.post_id]["sources"].add(post.source)
merged = list(candidates.values())
merged.sort(key=lambda item: len(item["sources"]), reverse=True)
return merged[:limit]
following = [
Post("p1", "ana", "following"),
Post("p2", "ben", "following"),
]
recommended = [
Post("p2", "ben", "similarity"),
Post("p3", "cy", "popular"),
]
for item in build_candidates(following, recommended):
post = item["post"]
print(post.post_id, sorted(item["sources"]))Here, p2 is returned once even though two retrieval methods found it. Its two sources may indicate that it is a strong candidate, but this is not the final decision.
Eligibility filters
Before or after retrieval, the platform applies eligibility checks. These checks remove posts that should not enter the ranking stage. Examples include:
- The user has blocked or muted the author.
- The post is deleted, private, or unavailable in the user's region.
- The post has already been shown too many times.
- The post violates safety, spam, or legal policies.
- The post is too old for the product's freshness rules.
- The user has already seen the same content through another format.
Filtering can happen at several points. Early filters save computation by preventing unsuitable posts from reaching later stages. Late filters can use more context, such as the exact position in the feed or the number of similar posts already selected.
Recall and cost trade-offs
Candidate generation aims for high recall. Recall is the share of relevant posts that the system successfully includes in its candidate pool. If a relevant post is never retrieved, the ranking model cannot recover it.
However, a larger pool costs more to score and filter. A smaller pool is faster but may miss useful content. Platforms therefore use multiple stages:
- Fast retrieval methods find a broad pool.
- Lightweight filters remove clearly ineligible posts.
- More detailed models score the remaining candidates.
- Final rules arrange the selected posts.
A common error is to treat retrieval as ranking. Retrieval asks, “Could this post be relevant?” Ranking asks, “Which eligible post should appear first?” Keeping these jobs separate makes the system easier to measure. Teams can test whether a change improves recall without confusing it with changes in final ordering.
Exercise
A user follows 500 accounts, but the feed only considers 200 recent posts from those accounts. A relevant post is older than the retrieval window and never appears. Which stage should you investigate first?
Show answer
Candidate generation. The post was excluded before ranking, so changing the ranker's score would not make it appear.