Tuesday, December 1, 2015

System Design SNAKE原则 (以NetFlix为例) | Now Now Now



http://www.jianshu.com/p/b628a2a573f5

Scenario 场景

这是每个系统设计的第一步,搞清楚我们的系统场景,为什么服务。我们的业务场景是什么样子的,都有哪些角色,怎么个流程?其实在这一阶段就是列出系统需要实现的功能有哪些。
接着我们把功能根据优先级和核心功能进行排序。比较互联网很快,我们先搞一个Version1.0上去,再来优化。

Needs 需求

很多人被这个中文翻译搞懵逼了,你不是在第一阶段就讲过需求吗?这里的needs是说咱们系统设计出来要满足什么样的用户量,需要咱们设计一个多么吊&牛X的系统。最好这个时候能拿出纸和笔来计算一下,咱们的DAU、并发量、QPS、TPS、峰值。Pls,remember:我们需要的是一个合适的系统,绝对不是一个可以满足100年都可用的巨牛逼的系统。

Application 应用

这一阶段,我们要做的是将我们的功能进行划分,分组成不同的模块。这样后边我们就可以团队分工开发,团队协作。
接着我们需要考虑的是关键的一些算法。比如缓存算法、分库算法等。
Service + Algorithm

Kilobyte 数据

  • 关系型数据库SQL Database
    • 小调查:Twitter的哪些信息适合放在关系型数据库中?
    • 用户信息 User Table
  • 非关系型数据库 NoSQL Database
    • 小调查:Twitter的哪些信息适合放在非关系型数据库中?
    • 推文 Tweets
    • 社交图谱Social Graph(followers)
  • 文件系统File System
    • 小调查:Twitter的哪些信息适合放在文件系统中?
    • 图片、视频Media Files
讲到这个地方其实我想总结一句:
  • 程序 = 算法 + 数据结构
  • 系统 = 服务 + 数据存储

Evolve 改进

这个阶段就是做优化和维护工作了,我们最好根据实际的需要去优化系统,满足系统不远将来的增长。选择一个最合适的方案而不是一个最好的方案。
https://xmruibi.gitbooks.io/interview-preparation-notes/content/SystemDesign/index.html
Steps (S - N - A - K - E)
  • Scenario: (Case/Interface)
  • Necessary: (Contain/Hypothesis)
  • Application: (Services/Algorithms)
  • Kilobyte: (Data)
  • Evolution

Scenario

Enumerate All possible cases

  • Register / Login
  • Main Function One
  • Main Function Two
  • ...

Sort Requirement

Think about requirement and priority

Necessary

  • Ask:
    • User Number
    • Active Users
  • Predict
    • User
      • Concurrent User:
      • Peak User:
        •  : c is a constant
      • Future Expand:
        • Users growing: max user amount in 3 months
    • Traffic
      • Traffic per user (bps)
      • MAX peak traffic
    • Memory (< 1 TB is acceptable)
      • Memory per user
      • MAX daily memory
    • Storage
      • Type of files (e.g movie, music need to store multiple qualities)
      • Amount of files

Application

  • Replay the case, add a service for each request
  • Merge the services

Kilobyte

  • Append dataset for each request below a service
  • Choose storage types

Evolution

  • Analyze
    • with
      • Better: constrains
      • Broader: new cases
      • Deeper: details
    • from the views of
      • Performance
      • Scalability
      • Robustness
System Design SNAKE原则 (以NetFlix为例) | Now Now Now



  • Scenario
  • Necessary: constrain/hypothesis
    1. Daily active user? Ask! eg. 5,000,000
    2. Predict
      1. User
        1. Average Concurrent Users = daily_active_user * average_online_time / daily_seconds
          = 5,000,000 * (30*60) / (24*60*60)
          = 104,167/s
        2. Peak users = average_concurrent_users * 6 = 625,000/s
      2. Traffic
        1. Video traffic speed = 3mbps
        2. MAX
      3. Memory
        1. Memory per user = 10KB
        2. MAX daily memory = 5,000,000 * 2 * 10 = 100GB
          (T级以内的内存都是可以解的)
      4. Storage
        1. Total movie = 14,000
        2. Movie storage (视频会有不同版本) = total_movie * average_movie_size = 14,000*50GB = 700TB
  • Application: service/algorithm 模块设计
  • Kilobit: data 数据设计, 不同数据的存储模型
    1. 比如用户服务可以用mysql, 查询逻辑强
    2. 电影文件就用文件存,不用数据库
  • Evolve: 和面试官沟通
    1. Step1: Analyze
      1. with
        1. More constrains
        2. New use cases
        3. Deeper, more details
      2. from the views of
        1. Performance
        2. Scalability
        3. Robustness
    2. According to 面试官, 加深某一部分的设计

  • Read full article from System Design SNAKE原则 (以NetFlix为例) | Now Now Now

    Labels

    Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

    Popular Posts