Courses › System Design › Question Breakdowns

Design TikTok (For You Feed)

Candidate generation, ranking and re-ranking, real-time session signals, cold start and instant playback.

Design TikTok's For You feed: an endless stream of short videos chosen for each user by a recommendation system, starting instantly on swipe, for over a billion users. Unlike News Feed, the feed doesn't come from who you follow — it's retrieved and ranked from the whole catalog in real time. It's a question about multi-stage recommendation (candidate generation → ranking), real-time user signals, serving short video with near-zero start latency, and the upload pipeline that feeds it all.

Requirements

Functional

  • Users swipe through a personalized feed of short videos (the For You page)
  • Users upload short videos, which become eligible for recommendation within minutes
  • Users like, comment, share, follow; watch time and skips are recorded
  • The feed adapts within a session to what the user just watched

Out of scope: live streaming, ads, messaging, the model training algorithms themselves.

Non-functional

  • Instant playback: the next video starts in < 200ms when the user swipes
  • Feed latency: a batch of recommendations in < 200ms
  • Scale: ~1B daily users, ~100B+ video views/day, ~50M uploads/day
  • Fresh: new videos and new user signals affect recommendations within minutes (even seconds for in-session signals)
  • Highly available; a degraded recommender should fall back to popular content, not an error

[!TIP] Funnel down the catalog in stages You can't score a billion videos per request. Production recommenders use a funnel: candidate generation cheaply retrieves a few thousand plausible videos from many sources, a ranking model scores them precisely, and re-ranking applies diversity and business rules. Each stage is ~10–100× smaller than the one before.

Capacity estimates

Core Entities

  • Video — ID, creator, duration, audio track, hashtags, renditions, content embeddings, safety labels
  • User profile — long-term interest embeddings, recent interactions (session), demographics, region
  • Interaction event — user, video, type (view, watch %, like, share, skip), timestamp
  • Feature store — precomputed user and video features served at low latency

API

GET  /v1/feed/foryou?count=8&cursor=...
→ { "videos": [{ "id": "v1", "playUrl": "https://cdn.../v1/720p.mp4", "cover": "...", ... }], "cursor": "..." }

POST /v1/events   [{ "videoId": "v1", "type": "watch", "watchedMs": 13200, "durationMs": 15000 }, ...]
POST /v1/videos   (resumable upload) → { "videoId": "v9", "status": "processing" }

High-Level Design

app = client "TikTok App" @0,1
feed = service "Feed Service" @1,1
cand = service "Candidate Generation\n(ANN, trending, follows)" @2,0
rank = service "Ranking Service\n(deep model)" @2,1
fs = cache "Feature Store" @3,1
cdn = cache "CDN\n(video renditions)" @1,2
ev = queue "Interaction Events" @2,2
rt = service "Real-time Feature\nUpdaters" @3,2
train = service "Online Training" @4,2
app -> feed : next batch
feed -> cand
feed -> rank
rank -> fs
app -> cdn : prefetch videos
app -> ev : watch / like / skip
ev -> rt
rt -> fs
ev -> train
  • The app requests the next batch. The feed service asks candidate generators for a few thousand videos: nearest neighbors of the user's interest embedding (ANN index), trending in their region, creators they follow, similar to recently watched, and a slice of fresh uploads to explore.
  • The ranking service scores candidates with a deep model using features from the feature store (user, video, cross features), predicting watch time, completion, like and share probabilities.
  • Re-ranking blends objectives, enforces diversity (no five videos from one creator), removes already-seen videos, and applies safety rules.
  • The app prefetches the next few videos from the CDN so swipes are instant.
  • Interaction events stream back to update real-time features and online training.

Deep Dives

1. Candidate generation

Each source returns hundreds of candidates; the union is deduplicated and passed to ranking. Retrieval must be fast (~20ms per source, run in parallel).

2. Ranking

A multi-task deep model predicts several outcomes per (user, video): expected watch time, completion, like, share, follow, skip. The final score is a weighted combination — the weights encode product goals. Ranking runs on GPUs/CPUs in batches of a few thousand candidates per request; features are fetched in bulk from the feature store.

3. Real-time signals

What makes the For You page feel responsive: a user who just watched three cooking videos to the end should see more cooking in the same session.

  • Interaction events flow through Kafka to stream processors that update session features (recent topics, recent creators, skip streaks) in the feature store within seconds.
  • Models are updated by online training (continuously consuming the event stream) rather than only daily batch retraining — ByteDance's Monolith system is a published example of this approach.

4. New videos: cold start

A new upload has no engagement data. The pipeline transcodes it, extracts content embeddings (visual, audio, text/captions) and safety labels, then gives it a small exploration audience. If early watch-through and engagement are strong, it's promoted to progressively larger pools; if not, it stops spreading. This "traffic pool" approach lets unknown creators go viral.

5. Instant playback

  • Transcode into a few renditions (and HLS/DASH for longer videos); short videos are small enough to download whole.
  • The client prefetches the first second or two of the next 2–3 videos in the feed batch (and covers) while the current one plays.
  • Popular videos are pushed to CDN edges proactively; the long tail is fetched on demand.

[!WARNING] Never let the recommender take the feed down If ranking is slow or down, return cached recommendations or regional trending instead of failing. Set strict timeouts per stage and fall back stage by stage — a slightly worse feed is far better than an empty screen.

6. Avoiding repeats and filter bubbles

Keep a per-user seen set (a Bloom filter of recent video IDs) to drop already-watched candidates. Re-ranking injects diversity (topics, creators) and a small amount of exploration so the feed doesn't collapse into one interest.

What's expected at each level

  • Mid-level: a feed service returning personalized videos, an upload and transcoding pipeline, CDN delivery with prefetching.
  • Senior: the retrieval → ranking → re-ranking funnel, multiple candidate sources with ANN retrieval, a feature store, interaction events feeding back, fallbacks.
  • Staff: real-time session features and online training, cold-start traffic pools, multi-objective ranking trade-offs, latency budgets per stage, and diversity/exploration to avoid filter bubbles.