A mock system design interview designs a TikTok-style short video platform around S3, CDN and a transcoding pipeline.
Amazon S3, because AWS already makes storing and serving large files reliable, saving the time of building an in-house store. S3 also ties directly to a CDN, with buckets in different regions, so a viewer in Mumbai reads a nearby copy instead of one machine in the US that becomes a single point of failure.
Video metadata is not organised or relational the way user data is, and its properties change: when the video was deleted or uploaded, duration, thumbnail, description. A flexible schema handles that. A key-value store is also faster than MySQL for single-key access, and easier to scale horizontally for the recommendation engine, user history and listing services that all read it.
200K videos a day at roughly 1 MB each gives 200 GB. Supporting about four formats, counted as roughly 2x because some files are smaller than others, makes 600 GB. Different resolutions add another 2x, since size keeps halving as resolution drops, so the estimate is 1.2 TB per day.
It goes through a workflow: first a validation check that rejects anything longer than 60 seconds; then a check that the video is appropriate, some kind of filter; then conversion into multiple formats. The file is divided into chunks, four parallel processes convert the formats, resolutions follow, and the chunks are combined again into 8 or 16 copies.
It reaches the video serving service, which first checks whose videos are being requested, then queries the user database and the video metadata key-value store by user ID. A list of video titles and thumbnails is returned first. Only once the viewer clicks a video does streaming begin, played from the CDN using just the video ID.
Consistency is not a key thing here; a video shown late in one country is acceptable. Availability is very important, and the system must be fault tolerant, so one Indian server failing never hides videos; an entire data centre would have to go down. Performance matters too: publishing an upload quickly and sending it to users quickly.
Ten million daily active viewers, from an assumed one billion Instagram downloads with about one in 100 watching each day; roughly 10 percent, one million, are very frequent users. Creators are far fewer, about one lakh, 100K. That puts the write-to-read ratio near 1 to 100, so reads far outnumber writes.
Only an acknowledgement, the code 202, meaning the request is accepted for the resource and the resource will then be created. Requests pass through a queue first, because creators cannot be rate limited to one file or ten files at a time, so every request is queued and sent for processing one by one.
It depends on resources and money. Akamai is a well-known provider, while Netflix has Open Connect, effectively its own CDN. Outsourcing brings SLAs: paying a lot while getting 99.98 percent when 99.99 percent was wanted is a big decision, as is build time. At Netflix's scale, building your own is worth the investment.
HTTPS, chosen because it is the protocol actually worked with, rather than guessing about FTP, whose differences would have to be looked up first. The file is not recorded live, it is just a large chunk of data that can be broken into chunks and packets, and HTTPS uses TCP, giving reliable and ordered transport.
“so what we want to do ideally is uh allow videos only of seven seconds”
“so using a combination of s3 plus cdn to serve files like images and videos is actually a good approach to have low latency”
“in general 2x of that is fine so I would say 1.2 TB is what we have”
“Basically what you have done is you have decoupled ingestion rate from processing rate”
“One place I would have liked to see you get to quickly would have been cost estimation”
“But it is better that I say that I have not worked on it rather than try to guesstimate something, right.”
“System Design Interview: TikTok architecture with @sudocode.” https://www.youtube.com/watch?v=07BVxmVFDGY. Transcript summary by WhipScribe, https://whipscribe.com/transcript-pages/system-design-interview-tiktok-architecture-with-sudocode.html.