System design interview: how to design comments and reply, likes button and total views on Youtube

System design interview: how to design comments and reply, likes button and total views on Youtube

Methodology: READ MF!

[Originally from the Post: System design interview: how to design a chat system (e.g., Facebook Messenger, WeChat or WhatsApp)]

Remind ourselves with the "READ MF!" methodology.

This is a follow up on the previous post: System design interview: how to design a video platform (e.g, Youtube, Netflix)

Requirements

First,
let‘s quickly about requirements. Likes and views are relatively
straightforward, users can torllerate a bit delay and inaccuracy. For
the majority case, as long as user clicks the button, it pluses one,
then it‘s fine. Sometimes it‘s not the case if videos have too many
likes, e.g., if a Youtube video already has 10K likes, you plus 1, it
still shows 10K, it‘s just the UI tricks you that it‘s toggled.

For
comments reply, there are a few different styles. The major ones such
as Youtube, Instagram and TikTok uses following style. It displays
comments (directly reply to video) based on order of likes and timestamp
(descending) and any reply to comments are only 1 on 1, meaning [email protected] How
are you, then [email protected] I am fine thank you and you? There is no more
indentation needed.

Reddit
uses the "block building" reply-to style (中文俗称"盖楼"), where it shows
which reply replies to which reply, and it needs to show the
indentations about those replies.

Estimation

For viral videos, say normally it has around 10M views

For likes, assuming 20% people liked a video, 10M * 20% = 2M likes

For comments, 1% people would leave a comment (we are lazy) 10M * 10% = 100K comments

For
the majority normal videos, it would probably has 1000 views and 100
likes top and maybe 10 comments, a relationship DB could solve it pretty
well.

Key designs and terms

Comments design

If you start building your product, just bootstrap it with a relational DB

Introduce
a comments table shard by video UUID, add a reply_to_uuid to know which
comment the reply is targeted to and leave it null for root comment.
Build an index on the reply_to_uuid

Select * from comments where reply_to_uuid is null order by comment likes desc, timestamp desc

If you need to see the replies to those comments, just

Select * from comments where reply_to_uuid is the_target_comment_uuid order by comment likes desc, timestamp desc

Even
if your product becomes Youtube scale, the comments would be around
100K for viral videos, the above solution would still works fine. Simply
add more capacity to better shard your comments using consistent
hashing, cache the comments would do the trick.

If you
need to build the Reddit tree structure, just sort it in memory. If the
problem can fit into memory, it becomes much easier.

The
extreme case is your comments section becoming a chat, then we can do
something like an append only in memory DB or redis cache keep appending
the values to the queue with async backup to DB.

Views and Likes count design

Similarly, when you bootstrap the
project, keep a counter in DB or in memory cache solves your problem
when traffic is low. If within one machine, you don‘t even need locks
just use compare and swap (CAS), atomic operations for counting, thread
safe.

If your product starts to become popular, add more capacity using
consistent hashing. Add in memory cache like Redis to count the values
(memory access time 100us vs disk access time 10ms. 100Kx improvement).
Could be further optimized using distributed counter, aggregating the
results together when read.

If you product becomes
YouTube scale, then
use offline counting. Build a pipeline to promote the videos from cold
to hot/viral once the view counts hit a certain threshold (say 1M). Use
async messaging like Kafka to ingest from those logs and pump it to data
warehouse, query it and update the values on a cron schedule. Of course
on the UI side, you need to toggle the like button, plus 1 if needed
(Sometimes you would see a 100K likes video, even if clicked the like,
the count would not be increased)

Baozi Youtube Video

References (Credits to original authors)

原文地址:https://www.cnblogs.com/baozitraining/p/12178850.html

时间: 2024-08-26 02:17:03

System design interview: how to design comments and reply, likes button and total views on Youtube的相关文章

System design interview: how to design a feeds system (e.g., Twitter, Instagram and Facebook news feed)

System design interview: how to design a chat system (e.g., Messenger, WeChat or WhatsApp) Methodology: READ MF! Please use this "READ MF!" framework for software engineer system interview purpose. Key designs and terms So far the best detailed

Material Design with the Android Design Support Library

Material Design with the Android Design Support Library 原文http://www.sitepoint.com/material-design-android-design-support-library/ Material Design,Android 5.0发布时为android app 和其他平台app引入的一门新的设计语言. 它带来了一些新的UI组件,如“Floating Action Button”.实施这些新组件,同时确保向后兼容

Design a Cache System

Design a Cache System Similar to our previous posts, we would like to select system design interview questions that are popular and practical so that not only can you get ideas about how to analyze problems in an interview, but learn something intere

practical system design with mef & mef[ trans from arup.codeplex.com/]

Practical System Design using MEF MVVM RX MOQ Unit Tests in WPF Posted on May 21, 2015 by Arup Banerjee Prelude The project is a simple Temperature Converter WPF Application which will allow user to convert from Celsius to Fahrenheit and vice versa.

How to Design Youtube (Part I)

How to Design Youtube (Part I) One of the most common types of system design interview questions is to design an existing popular system. For example, in the past, we've discussed How to Design Twitter, Design Facebook Chat Function and so on so fort

RESTful API Design With NodeJS & Restify

http://code.tutsplus.com/tutorials/restful-api-design-with-nodejs-restify--cms-22637 The RESTful API consists of two main concepts: Resource, and Representation. Resource can be any object associated with data, or identified with a URI (more than one

Learning JavaScript Design Patterns -- A book by Addy Osmani

Learning JavaScript Design Patterns A book by Addy Osmani Volume 1.6.2 Tweet Copyright © Addy Osmani 2015. Learning JavaScript Design Patterns is released under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 unported license. It

Domain Driven Design and Development In Practice--转载

原文地址:http://www.infoq.com/articles/ddd-in-practice Background Domain Driven Design (DDD) is about mapping business domain concepts into software artifacts. Most of the writings and articles on this topic have been based on Eric Evans' book "Domain Dr

Honeywell.UniSim.Design.R430/R400

UniSim Design Suite帮助过程工业在生命周期中提高生产力和利润率.强大的仿真和分析工具.实时的应用软件以及集成的工程解决方案的都有助于公司提高设计水平.优化生产工艺.提高决策能力.UniSim Design Suite与UniSim操作和优化套件所创建的模型完全兼容,并支持与它们之间的互操作.电 话TEL:18980583122 客 服 QQ:1140988741 邮件(Email):[email protected] [email protected]UniSim能让用户迅速确