System Design - YouTube

Overview

  1. Clarify the requirements 了解系統需求
  2. Capacity Estimation 頻寬存儲估計
  3. System APIs 系統API設計
  4. High-level System Design 系統系統設計
  5. Data Storage 數據存儲設計
  6. Scalability 優化 Scalability

Step1: Clarify the requirements 了解系統需求

  • Feature Requirements
  • Traffic/User size(e.g., Daily Active User) 服務流量的大小

Nobody expect you design a complete system in 30-45 mins

Align with interviewers on 2-3 components to focus in the interview

系統設計面試重點:要和面試官達成一致

Type 2: Non-Functional Requirement

為了保證 Availability犧牲了 Consistency
設計重點:系統面對比較大流量時的Scalability和Low latency

  • Consistency
    • Every read receives the most recent write or an error
    • Tradeoff with Availability: Eventual consistency(最终一致性)
  • Availability
    • Every request receives a (non-error) reponse, without the guarantee that it contains the most recent write
    • Scalable
      • Performance: low latency(because it is watching video)
  • Partition tolerance(Fault Tolerance) 系統的容錯性
    • The system continues to operate despite an arbitrary number of messages being dropped(or delayed) by the network between nodes

Step2: Capacity Estimation

Why Capacity Estimation?

  • Evaluate candiadate’s analytical skills & system sense
  • Helpful for identifying system bottlenecks in order to improve system scalability.

Replication(數據的備份):通常需要在一個數據中心內把數據備份三份
為了系統的可用性: 同一個文件會被分佈到不同的數據中心

這就需要9倍的儲存空間

DAU = Daily active user

Step 3: System APIs

Offset: 影片的時間戳(TimeCode)

codec: 影片的編碼格式

resolution:分辨率(主要取決於頻寬的大小,用來優化觀影體驗)

Step 4: High-level System Design

Metadata:影片的標題描述等

影片本身會存到Distributed Media Storage

上傳的影片需要經過轉碼處理成不同格式和分辨率的視頻 -> 需要異步處理(Using Processing Queue)

Video Processing Service: 將處理完的影片跟縮略圖存放到文件系統

同時在metadata數據庫當中更新影片跟縮圖的存放地址

For lower latency: CDN(push data to the server that is closer to user)

Video distributing Service:負責將影片和圖片分發到CDN的各個節點上

Completion Queue: 異步處理, 當處理完之後往這個隊列添加任務

  1. 下載影片然後把一個影片分成小片段
  2. 對影片解碼再編碼(將影片變成不同的格式和分辨率)
  3. 提取影片縮略圖
  4. 用ML算法來做 video content understanding

一般熱門的影片會從CDN上stream給用戶
冷門的視頻則由原Data Center stream to user

Scenario 2

Video Playback Service: 主要用來負責影片播放

Host Identify Service: 用來對影片的地址進行查找也就是說給定一個video給定一個user的IP地址,然後給定用戶的設備信息,查找離這個用戶最近的並且儲存有這個影片的CDN的位置

如果找到了就把位置回傳給用戶,用戶就可以觀看影片了, 沒有找到就從Data center找影片給用戶觀看

Metadata/User:從數據庫直接讀取影片的標題描述等

Step 5: Data Storage

PK = primary key

Step 6: Scalability

找出系統瓶頸,然後提出解決方案和優缺點分析

解決方案:把數據進行多份拷貝分發到不同的機器上,這樣多台機器就能serve不同的requests


常見的方法:使用primary-secondary

Pros:

  • Availability:隨時都可以讀數據而不用被寫操作影響

Cons:

  • 用戶不一定能讀到最新的數據(對用戶沒有多大影響)

Optimization 3: Caching

Netfilx-Example(Put Cache in ISP)

CDN

Reference

花花醬 YouTube


System Design - YouTube
https://bominc0624.dev/2023/04/09/system-design-youtube/
Author
Bomin Chuang
Posted on
2023年4月9日
Licensed under