MLCrack

    ML SYSTEM DESIGN (DEEP DIVES) · INTERVIEW QUESTION

    Design X (Twitter) home timeline ranking — including in-network and out-of-network candidate sources.

    🔴 advanced · Recommendation / Feed

    Hint: Multi-stage ranking, light vs heavy ranker, real-time signals, diversity quota, interleaving experiments.

    Answer

    1. Problem Formulation

    "Design X's (Twitter's) home timeline" — clarify the surface first.

    Clarifying questions:

    • Surface? The "For You" personalized feed (not the chronological "Following" tab).
    • Scale? ~500M MAU, ~250M DAU, each user pulls ~50 tweets per session, multiple sessions/day. Corpus of ~500M tweets/day with a hot window of ~1 week.
    • Objective? Maximize meaningful interactions — reply, retweet, profile-click, dwell time on tweet detail. Not raw scroll velocity.
    • Latency? p99 ≤ 300 ms feed assembly; we have ~150 ms for ranking inside that.
    • Constraints? Real-time freshness (a tweet 2 minutes old should be eligible for ranking), out-of-network discovery (~50% of feed must be from accounts the user doesn't follow), safety policies.

    Why ML? With 500M tweets/day and millions of authors followed, no heuristic can pick 50 that the user will actually engage with. Reverse-chronological loses to ranking by ~30% engagement.

    ML framing: multi-stage learning-to-rank with mixed in-network and out-of-network candidate sources.

    2. Metrics

    Offline:

    • Weighted NDCG@50 where weights are the engagement-value of each action (reply > retweet > like > dwell).
    • Recall@500 for the retrieval stage against held-out engaged tweets.
    • Calibration per action — needed because downstream policies (ads insertion, diversity) consume the probabilities.

    Online:

    • DAU, sessions per DAU, time per session.
    • Reply rate, retweet rate, profile-click rate.
    • Guardrails: report rate, "show less often" rate, unfollow rate, out-of-network share (must stay ~50% — collapsing to all in-network is a known failure mode).
    • Author diversity: Gini of impressions per author bucket.

    Trade-off: ranking purely by predicted engagement collapses to a few high-engagement authors. Diversity and out-of-network targets are constraints, enforced in the re-ranker layer, not in the loss.

    This is the opening of a longer walkthrough. Read the full answer in the topic explorer, free.

    Likely follow-up: How do you prevent the feed from collapsing onto a few high-engagement authors?