0% completed
YouTube Likes Counter: System Definition
On This Page
Step 1: System Definition
Step 1: System Definition
Watch any video on YouTube and look at the numbers around it. The video has a like count, and every comment under it has one too. In this case study, we design the backend behind those numbers.
The job of the system is easy to state. It records each like and dislike, for videos and for comments, and it updates the total counts. It returns those counts with a short delay (low latency). It must do this for millions of users at the same time, while holding billions of past reactions.
One counter is easy. The hard part is that many users change the same counter at once. A popular video draws reactions from millions of viewers, and every one of them expects to see a correct count.
Key entities. Before we draw anything, we name the things the system stores. There are four. The diagram shows them and how they connect.
- User. A viewer with a unique
userID, for example User A with id=123. Users create the reaction events. - Video. A content item with a unique
videoID, for example Video V with id=XYZ1. The system tracks total likes and dislikes for every video. - Comment. A user's response to a video, with a unique
commentID. Like videos, comments have total like counts. - Reaction (Like or Dislike). The link between one user and one specific video or comment. It records the type, Like or Dislike, and metadata like a timestamp. This is the record that answers "has this user already reacted to this item?" A user can toggle or remove a reaction at any time.
Notice the split in this list. Reaction records store who reacted to what. The counts on Video and Comment are the totals everyone reads. Keeping the two consistent is most of the work in the steps ahead.
One minute of real traffic. Let's follow user Alice, who watches the video "Funny Cats" (videoID: abc123).
- Alice clicks the thumbs up button. The system records a Like linking Alice to the video, then adds one to the video's like count.
- Alice reads a comment (
commentID: cmt99) and likes it. The system records that reaction and updates the comment's count. - At the same moment, user Bob clicks thumbs down on the same video. The system records a Dislike and adds one to the video's dislike count.
Alice and Bob never waited on each other, and neither count went wrong. Keeping that true while millions of users react to popular content at the same time is the whole job of this design.
Next: Step 2, where the requirements are defined.
Reading Progress
0%
On This Page
Step 1: System Definition