get Top k YouTube video

get Top k YouTube video

Functional Requirement

get top k YouTube video
get the number in 1min, 1 hour, 1 day or all time

Non-functional Requirement

service availability >> consistency(some service down)
We should support a massive number of videos.
We should support a massive incoming request.
search needs to be fast, we need to query top k fast < 200ms with time window setup

Core Entities

  • Video
  • Count
  • Window size(1 second, 1 day, 1 month)

API Design

get view/videos?topK={}&window={}

High Level Design

very simple solution:
在这里插入图片描述

这里有个点:
为什么我们不写进db? 因为读写操作没有in-memory system 快,在我们有很多很多的video的时候这个system 更快
这里有点不一样的时候是计算是挺重要的:
Billion级别的 videos
假设10B * (16Byte) = 160 GB,这完全是能用in memory system handle的

Dive Deep

service availability >> consistency(some service down)
we could have multiple snapshots of in memory system, which could be in the s3 storage

如何做data partition?
那我们可以有一些random generator给他们分配一下partition, 然后把它们分配到不同的 in memory system里面。

get the number in 1min, 1 hour, 1 day or all time?
we can use kafka
具体例子:
假设我们有一个1小时的时间窗口,当前时间是 12:00。

"上升沿"消费者:从最新偏移量(比如 10000)读取新消息。
"下降沿"消费者:

计算目标时间:11:00
找到 11:00 对应的偏移量,假设是 9000
从偏移量 9000 开始读取消息
读取到偏移量 9500 时,发现消息时间已经超过 11:00,暂停消费
在 12:01 时,重新计算目标时间(11:01),找到对应的新偏移量(可能是 9010),从这里继续消费。

Final high level design

请添加图片描述

  • 11
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值