Design TikTok
Understanding the Problem
🎵 What is TikTok? TikTok is a short video app. Creators record clips from a few seconds to a few minutes long, and viewers scroll through a full-screen, vertical feed where each swipe shows the next video, already playing. Its main screen, the "For You" feed, is built almost entirely from recommendations rather than from accounts you follow, which is what makes it different from a classic social feed.
Instagram Reels and YouTube Shorts are the same problem inside a bigger app. The video pipeline and the swipe-to-play feed are identical. What changes is where candidates come from, because those apps already have a follow graph and a huge back catalog to draw on. We'll come back to that at the end of the deep dives.
Functional Requirements
Agree with your interviewer on scope first. TikTok has editing tools, effects, music licensing, live streams, DMs and a shop. We'll focus on the loop that defines the product: post a video, and watch an endless personalized feed.
Core Requirements
- Users should be able to upload short videos (up to a few minutes) with a caption.
- Users should be able to watch a personalized, endless feed of videos, where each swipe plays the next one immediately.
- Users should be able to like, comment on and share videos and follow creators, and those actions should shape what they see next.
Below the line (out of scope)
- In-app editing, effects and the sound library.
- Live streaming, DMs and the shop.
- Search and hashtag pages.
- Content moderation (we'll mention where it plugs in).
Non-Functional Requirements
Ask for scale. We'll assume 500 million daily active users who each watch about 100 videos a day, and 20 million uploads a day.
Core Requirements
- The next video should start playing with no visible delay when the user swipes (under ~200 ms from swipe to first frame).
- A page of feed results should come back in under ~200 ms at p99.
- The feed should react to what the user just did within the same session, not tomorrow.
- Playback and the feed should be highly available. A new upload can take tens of seconds to appear, and like counts can lag by a few seconds.
- The system should scale to on the order of 600k video views per second.
Below the line (out of scope)
- Strong consistency for counts. Eventually consistent like and view counts are fine.
- Training the ranking models. We'll design the serving side and treat models as black boxes with inputs and outputs.
The arithmetic:
- Views: 500M × 100 = 50B views a day, about 580k per second on average, and over a million at peak.
- Feed requests: if one request returns 10 videos, that's about 58k feed requests a second on average. Each one ranks hundreds or thousands of candidates, so the ranking tier scores on the order of tens of millions of (user, video) pairs per second.
- Egress: say each view streams about 15 seconds at 1.5 Mbps. That's 1.5 Mbps × 15 s ÷ 8 ≈ 2.8 MB per view, and 50B × 2.8 MB ≈ 140 PB a day, or about 13 Tbps on average. Prefetching videos that are then skipped adds to that.
- Uploads: 20M a day at around 30 MB each is about 600 TB of raw video a day.
Two numbers should jump out. First, the ranking work per request is large, so "score every video for every user" is impossible and we need a funnel. Second, the latency budget for playback is set by the swipe, not by the network. The only way to start a video in under 200 ms on a mobile network is to have it on the phone before the user asks for it.