1) user should be able to see total views on a video.
2) all the views should be recorded.
3) creator should see the analytics of their videos.
1)system should be available all the time.
2)system should be able to distinguish fake views.
Let's assume there are 500M users and each user on average watches 10 videos daily.
total api calls 5Billions.
Each api request will have
userId 16 bytes
videoId 16 bytes
time 8 bytes
total 40Bytes * 5 Billion = daily 0.2GB.
Over 5 Years we will need 2TB.
we will have one api for counting the view
view(user_id, video_id, timestamp)
below api for analysis
analyze(user_id, video_id)
Since storage requirements is well within limit we can use a RDBMS and as well as NoSQL DB where videoId can be an index. This index can be used for analytics.
We will have aim for eventual consistency here, there are gonna be lots of views and writing each view directly to DB is not a feasible solution. Instead we can store the views for videos in a redis cache and will eventually update the view to DB in case of cache expiry and eviction. This also reduced load on db for view count as well. For less popular videos we can directly make the update to DB, or use a bigger cache to store all videos.
user can also analyze the views on his video. user will call the analytic service, this will authorize user using auth service and we can query the db based on video Id.
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?