Estimate the scale of the system you are going to design...
API design
Host - www.youtube.com
GET /v1/video/:videoId?viewCount=?
PUT /v1/video/:videoId/view
{
timestamp:
}
Database design
Video Table
ID (PK)
UserId (FK)
ViewCount
Timestamp
View table
Id (PK)
VideId (FK)
UserId (FK)
timestamp
High-level design
Client (Browser)
Load Balancer
Server
DB
Request flows
User renders a specific video from the server.
While watching the video, if the user has watched atleast 50% of the video, the client triggers a PUT request to the server to increase the video view count.
There is kafka queue to queue the views for increased throughput. The consumers fetch the data from Kafka queue and batch write the views to the DB for better throughput.
Websocket connection between client and server to get real time view count updates.
Detailed component design
Trade offs/Tech choices
Load balancer for routing.
Kafka for queueing the view requests to the DB.
Websocket connection between client and server to get real time updates.
Just clicking on a video shouldn't increase view count.
Failure scenarios/bottlenecks
Horizontal scaling for avoiding downtime and no single point of failure.
Future improvements
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?