Sub topic 1
Why feeds are ranked instead of sorted by time
Prerequisites
You should have used social media apps and be comfortable reading short Python. You should also know that a probability is a number from 0 to 1.
Why feeds are ranked instead of sorted by time
A chronological feed shows the newest post first. It is simple and easy to explain. However, most users follow hundreds of accounts, and many posts arrive each minute. A time-sorted list can bury the posts a user would care about under low-value updates.
A ranked feed orders posts by predicted value to the user. The platform estimates how likely you are to like, comment on, or hide each post, then sorts by those estimates. Ranking trades simplicity for relevance.
What a feed is trying to optimize
A feed has goals, and they are not always the same. A platform may want users to stay longer, return more often, or feel satisfied with what they see. Likes and comments are easy to measure, so they often stand in for these goals. That substitution matters. A proxy metric can reward content that provokes strong reactions even when users do not enjoy it. The choice of what to optimize belongs to the platform, and it shapes every later stage.
Narrowing millions of posts to a candidate pool
Scoring every post for every user is too expensive. The system first builds a candidate pool, often a few hundred to a few thousand posts. Candidates come from accounts you follow, topics you engage with, and popular content. Only this pool goes to the costly scoring step.
The signals a ranker looks at
A ranker converts each candidate into a feature vector, a list of numbers that describe the situation. Signals usually fall into four groups:
- User features: past behavior, stated interests, and recent activity.
- Author features: how often you interact with this creator, and how well their posts perform.
- Post features: age, media type, language, and early engagement counts.
- Context features: time of day, device, and current session length.
from dataclasses import dataclass
@dataclass
class Candidate:
post_id: str
author_follow_days: int
post_age_hours: float
has_video: bool
early_likes: int
def to_features(c: Candidate) -> list[float]:
return [
min(c.author_follow_days, 365) / 365,
1 / (1 + c.post_age_hours),
1.0 if c.has_video else 0.0,
min(c.early_likes, 1000) / 1000,
]
post = Candidate("p1", author_follow_days=200, post_age_hours=2, has_video=True, early_likes=150)
print(to_features(post))A signal is evidence about a post, not a verdict on its quality. The ranker learns how much each signal matters from past behavior, so a signal that predicted engagement last month may predict less today.
Exercise
Using to_features, what is the second feature value for a post that is 1 hour old?
Show answer
1 / (1 + 1) = 0.5. The second feature is 1 / (1 + postagehours), so an age of 1 hour gives 0.5.