Skip to content

Design TikTok

A system design interview walkthrough for a short-video for-you feed like TikTok: the ranking funnel, fresh signals, cold start and prefetch.

Advanced22 minUpdated 2 December 2026

Before this: Design Instagram, Batch vs Stream Processing, Embeddings & Vector Search

"Design TikTok" is a question about a feed, but not the feed you may be thinking of. In Design Instagram and Design Twitter, the hard part is fan-out: delivering posts from the accounts you follow. A "for you" feed has no follow graph to walk. The system must choose, from a billion videos, the next ten that this person is most likely to keep watching, and do it in well under a second.

The interviewer is testing whether you recognize that the problem moved from data movement to ranking at scale. Can you describe a multi-stage funnel and say why one model cannot score everything? Do you understand how a signal from thirty seconds ago reaches the next page of results? And what do you do with a video that nobody has seen yet?

The video bytes themselves come from a CDN, as in the other video questions, and we only touch on them for prefetching. The ranking design owes a lot to ML pipelines and feature stores.

Clarify the requirements

Functional requirements:

  1. A user opens the app and immediately sees an endless vertical feed of short videos.
  2. Each video autoplays, loops and can be liked, shared, commented on, or skipped with a swipe.
  3. Creators upload videos that are processed and become eligible for the feed.
  4. The feed adapts to what the user watches, within the same session.
  5. A following tab exists (mention it, and say it is the Instagram problem).

Out of scope, said aloud: the upload and transcoding pipeline (see Design YouTube), comments, direct messages, ads insertion, creator monetization.

Non-functional requirements: these decide the architecture.

  • The next video is ready before the user swipes. A feed request should return in about 200 ms, and the next videos should already be buffered.
  • Relevance is the product. The watch-time and completion signals are the metric, and a small ranking improvement is worth a lot.
  • Fresh signals matter. A user who watches three cooking videos in a row should see more by the fourth, not tomorrow.
  • New videos need a fair chance. If only proven videos are shown, nothing new can ever become popular, and creators leave.
  • Safety applies before ranking. Content that violates policy must not be eligible, however well it would score.

Estimate the scale

Assume 300 million daily active users, each watching about 100 videos a day and generating about one engagement event per video (watch time, like, share, skip).

Events: 300M × 100 = 30 billion a day, or 30B ÷ 86,400 ≈ 350,000 per second on average, and about 1 million per second at peak. At about 100 bytes each, that is 1.1 PB a year of raw events.

Feed requests: the app asks for a batch of 10 videos at a time, so each user makes about 10 requests a day. 300M × 10 = 3 billion a day, about 35,000 per second, and about 105,000 per second at peak.

Ranking work: if each request scores 200 candidates with the heavy model, that is 35,000 × 200 = 7 million model scores per second on average. Peak is three times that.

Video bytes: a 20-second clip at 1.5 Mbps is about 3.75 MB. 100 videos a day is 375 MB per user, and 300M users is 112 PB a day, or about 10 Tbps averaged over the day. The CDN carries it.

The funnel: the corpus is about a billion eligible videos. The heavy model can afford to see about 200 per request. Between those numbers is a five-million-to-one reduction, which is the design.

"35,000 requests a second would be easy if each were a lookup. The cost is the 7 million model scores a second, so you cannot score the corpus. You need stages that cheaply shrink a billion videos to a thousand, then to 200, then to ten, with the expensive model only at the end."

The capacity estimator reproduces the event rate and the 1.1 PB.

API and data model

GET  /v1/feed?cursor=<token>&n=10        -> { videos[{id, manifestUrl, ...}], nextCursor }
POST /v1/events   [{ videoId, type, watchedMs, durationMs, ts }]   (batched by the client)
POST /v1/videos   { upload metadata }    -> eligibility pipeline
video_features   (video_id PK, embedding, topics, language, age, quality_score, stats...)
user_features    (user_id PK, long_term_embedding, recent_events[], language, region)
seen             (user_id PK, video_id CK, ts)         -- recent window, TTL
events           append-only stream, keyed by user_id

The non-obvious choice: the client batches events and sends them every few seconds, and the feed request returns a few more videos than shown, so the client always has a short queue and a slow network does not stall the swipe.

High-level design

We simulate the serving path: the app calls a feed API, which reads candidates from a cache and a user-signals store, and publishes engagement events to a stream that ranking workers consume to refresh the candidate cache.

The feed API reads candidates from Redis and signals from Cassandra, and streams events through Kafka to workers that refresh the candidates.appfeed apicandidate cacheuser signalsengagement streamranking workers
The feed API reads candidates from Redis and signals from Cassandra, and streams events through Kafka to workers that refresh the candidates.
  • The feed API serves each request from the candidate cache and the user's recent signals.
  • Engagement events flow through Kafka to ranking workers, which write fresh candidates back to the cache.
Describe this diagram

Components

  • app (Client)
  • feed api (Service)
  • candidate cache (Redis)
  • user signals (Cassandra)
  • engagement stream (Kafka)
  • ranking workers (Service)

Connections

  • app sends to feed api
  • feed api sends to candidate cache
  • feed api sends to user signals
  • feed api sends to engagement stream
  • engagement stream sends to ranking workers
  • ranking workers sends to candidate cache

Run it, then try dropping the candidate cache or scaling down the ranking workers. A stale candidate list is what the user feels first.

The read path: the API loads the user's recent signals, fetches a precomputed list of candidates from the cache, runs the final ranking and diversity steps, removes videos already seen and returns ten.

The write path: the client batches events, the API acknowledges at once and appends them to a stream, never to a database on the request path.

The learning loop: workers read the stream, update the user's recent-activity features within seconds, and refresh the candidate list. Training of the larger model happens offline on the same events.

The interesting problem: the ranking funnel

Choosing ten videos from a billion for one person, in 200 ms, is a search problem in which the cost per candidate rises as the list shrinks.

Approach A: rank everything by global popularity

Keep a list of the most-watched videos and return the next unseen ones.

Good: trivial, cheap and cacheable.

Bad: it is not personal. Everyone sees the same videos, niche creators never surface, and a new video cannot enter the list until it already has views.

Approach B: score every video with one big model

Run the best model against every eligible video for this user.

Good: the best possible ordering, in theory.

Bad: a billion scores per request, times 35,000 requests a second, is not computable. Even restricting to a tenth of a percent of the corpus is orders of magnitude over budget.

Approach C: a funnel of increasingly expensive stages

Each stage narrows the set and spends more compute per item:

  1. Retrieval (billions to about 1,000). Several cheap sources run in parallel: nearest neighbors of the user's embedding in an approximate vector index, videos from creators and topics the user engaged with, videos liked by similar users, trending in their region, and a slice of new videos for exploration. Merge and deduplicate.
  2. Pre-ranking (about 1,000 to 200). A small, fast model drops the clearly poor fits.
  3. Ranking (200 to about 30). The heavy neural model predicts several outcomes for each candidate, such as completion, like and share probabilities, and combines them into one value score.
  4. Re-ranking (30 to 10). Apply rules and diversity: no three videos from one creator in a row, mix topics, filter anything already seen, enforce safety and policy labels, and insert exploration slots.

The funnel is the recommended answer, and the sentence that earns credit is: cheap and wide first, expensive and narrow last.

The recommendation is also precomputed where possible. For an active user, a background worker keeps a ready list of a few hundred ranked candidates in the cache, refreshed as new events arrive. The request path then re-ranks the head of that list with the latest signal, instead of running retrieval from scratch each time.

The second decision: cold start and exploration

A system that only shows what has proven popular is stuck in a loop. Two cold-start problems follow.

A new video has no history. Give it a test pool: show it to a small audience of a few hundred people chosen by its content features (topic, language, audio) and the creator's past audience. Measure completion, likes and shares against the baseline for videos of its length. If it beats the baseline, promote it to a pool ten times larger, and repeat. This is staged exploration, and it makes sure good new videos are found within hours.

A new user has no history. Start from region, language and device, with a broad popular mix and high diversity. Each swipe is a strong signal, so the feed narrows within a dozen videos, which is why events must reach the feature store quickly.

Reserve a fixed fraction of slots, such as 5% to 10%, for exploration for every user, so the system keeps learning even about people it thinks it understands.

Bottlenecks and failures

Feature store latency. The heavy ranker needs user and video features for 200 candidates, which is a large fan-out of key-value reads. Fetch them in a single batched call, co-locate the store with the rankers, and cache video features, which change slowly.

Event ingestion lag. If the stream backs up, personalization goes stale and the feed feels repetitive. Track the age of the newest processed event, and fall back to the long-term embedding when recent activity is unavailable.

Model rollout risk. A bad model can silently lower engagement for millions of people. Release to a small percentage with a control group, compare watch time and skip rates, and keep the previous model loaded for instant rollback.

What if the ranker is down? Serve from the precomputed candidate list in the cache, ordered by the last known scores. If that is unavailable too, return regional popular videos. The feed is never empty.

Trade-offs to name aloud

  • A funnel instead of one model: the cost fits the budget, but each stage can lose a video the later stage would have liked, so retrieval recall matters most.
  • Precomputed candidates: low latency and cost, at the price of slightly stale personalization. The final re-rank on fresh signals closes most of the gap.
  • Exploration slots: short-term engagement dips a little in exchange for discovering new creators and keeping the system learning.

What interviewers listen for

  • A working answer: upload and CDN for videos, an event log of views and likes, a recommendation service returning videos, and a cache.
  • A strong answer: a funnel of retrieval, ranking and re-ranking with numbers that show why, a feature store with fresh signals through a stream, precomputed candidates, and an event pipeline that does not block the request.
  • A standout answer: also handles cold start for videos and users with staged test pools and exploration slots, names the optimization target and its risks, plans model rollout and rollback, falls back gracefully when the ranker fails, and thinks about prefetch cost.

Check your understanding

Common mistakes

Treating it as a fan-out problem. Copying posts to followers is the right tool for a following tab and the wrong one for a for-you feed. Say which problem you are solving.

Forgetting cold start. Without it, the feed is stuck on yesterday's hits and new creators never appear.

Optimizing clicks. For an autoplaying feed, clicks are not the goal. Watch time and completion are, with guardrails.

No fallback when the ranker fails. A feed that returns an error on a model outage is worse than one that shows slightly stale popular videos.

Practice

The heavy ranker's latency doubles from 60 ms to 120 ms during the evening peak, and p99 feed latency exceeds 400 ms. What do you do?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

Consider what you can cut from the work, what you can precompute, and what you can degrade safely.

Show a strong answer

Cut the candidate count dynamically. The ranker's cost is roughly proportional to candidates. If the budget is slipping, reduce the pre-ranker's output from 200 to 100 when latency crosses a threshold. Quality dips slightly, and latency drops by about half.

Use the precomputed list more. For active users, serve the head of the cached ranked list and re-rank only the top 30 with fresh signals. This turns a 200-candidate job into a 30-candidate one.

Set a deadline per stage. Give the ranker a time budget. If it exceeds that, return the pre-ranker's order. A slightly worse feed in time beats a perfect one that is late.

The pattern worth keeping: build quality knobs (candidate count, model size, deadline) into the funnel so you can trade a little relevance for latency instead of failing.

Creators say that videos from small accounts never get views. How would you diagnose it and change the system?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

Look at where in the funnel small creators could be lost and what you measure about new content.

Show a strong answer

Find the stage where they drop out. For a sample of new videos, log how far each gets in the funnel: retrieved, pre-ranked, ranked, shown. If most are lost at retrieval, no source is recommending them. If they are shown and perform badly, the issue may be content, not the system.

Check the exploration path. If the test pool is too small or restricted to the creator's few followers, the video never collects enough signal to be judged. Size the pool so that a decision has statistical confidence, and pick its audience by topic and language, not only follow graph.

Check for popularity bias in ranking. A model that uses past view counts as a feature rewards incumbents. Use rates (completion per view) instead of totals, and add an exploration bonus for uncertainty.

The pattern worth keeping: a feedback loop that rewards past success will starve new entrants, so measure the funnel for newcomers and build exploration in on purpose.

Key takeaways

  • A for-you feed is a ranking problem, not a fan-out problem.
  • Use a funnel: retrieval, pre-ranking, ranking and re-ranking, with compute rising as the list shrinks.
  • Do the arithmetic: 35,000 requests a second times 200 candidates is 7 million scores a second.
  • Keep signals fresh with a stream and an online feature store, and send events off the request path.
  • Design for cold start with test pools and exploration slots.
  • Degrade, don't fail: cached candidates, then popular videos.

Further reading

  • P. Covington, J. Adams and E. Sargin, "Deep Neural Networks for YouTube Recommendations", ACM RecSys (2016): the two-stage candidate generation and ranking structure.
  • H.-T. Cheng et al., "Wide & Deep Learning for Recommender Systems", DLRS workshop (2016): combining memorization and generalization in a ranker.
  • C. A. Gomez-Uribe and N. Hunt, "The Netflix Recommender System: Algorithms, Business Value, and Innovation", ACM Transactions on Management Information Systems (2015): evaluation and the role of exploration.

Check yourself

3 questions in this lesson. Answer each once to complete it.

Practice this

Lessons in this track