In this article, we would go through a system design interview question and details solution. We would also provide the complete system architecture.
We would cover the following:
- Functional Requirements
- Non-Functional Requirements
- API Endpoints
- Choice of Database and Schema
- Cache and Precache Service
- Handling Scaling
- The Complete Architecture
1. Functional Requirements
- Users should be able to upload videos
- User should be able to view
- Users should be able to comment on a video
- Users should be able to other users
- Users should be able to like video
- Users should be able to favorite video
- User profile management
2. Non Functional Requirements
- High availability about 99.999%
- Latency – we are interested in how quickly the video timeline is loaded.
- Scalability
- 1 million daily active users
- A single video is about 5MB
- A user uploads 2 videos per day
- User metadata of 2K per user per day
- Consistency
3. API Endpoints
- /uploadVideo – a POST endpoint – this endpoint would send the video object to some data store. The video would be send to a blob store while the video metadata is sent to a relational database.
- /viewFeed or userTimeline – a GET endpoint that would retrieve a list of videos to display on the user timeline. We would like to preload this data using cache
- /like – this is the endpoint for users to like a video. It sends data to the likes table
- /follow – an endpoint for users to follow other users. It sends data to the followers table
- /comment – and endpoint for users to comment on a video
4. Choice of Database Schema
We would like to use a relational database. The reason is that we would storing structured data and would be doing lots of joins, relationships and queries NoSQL is suitable to non-structured data like documents, blogs etc.
We would need the following tables on the minimum
- videos – timestamp, metadata, userid
- followers – userid, followerid
- likes – userid, videoid
- comments – userid, videoid, comment
The basic database structure is given below. It could be much more involved, but we just give the basics here since we are looking at interview scenario.

5. Cache and Precache service
The precache services runs in the background on schedule. It could also run based on user request. In this case, we would like the user timeline to be pre-build and saved in a cache. So we need to have worker which is a read-only DB that where the precache service would read from.
6. Handling Scaling
So how do design for scalability for situation of spike in user activity.
CDN – place the API endpoints behind a CDN which means that the services are replicated across regions. The idea is that when a video is uploaded and million of users needs to access it, then the first time it is accessed, it is cached in a CDN. Therefore, subsequent users simply fetch from the CDN.
LoadBalancing – a load balanced in front of the API endpoints would also improve performance since it would route traffic based on some efficient algorithm. I would also be used to achieve high availability with possible zero downtime
Sharding – this is a horizontal partition of data in the database. This may be necessary for the write DB
The basic system architecture is given below:
