九章算法-系统设计#1

Typical System Design questions

Type_1: Desgn XXX System
Type_2:Design specific components in certain system

4S 分析法

重点:

- Ask Before Design: 问清楚再动手设计,切记不要做关键词大师
- No more no less:不要想射设计最牛的系统,要设计够用的系统
- Work Solution First:先设计一个基本能工作的系统,然后再逐步优化
- Analysis is important than solution: 通过分析过程展示知识储备,权衡各种设计方式的利弊
  • Scenario 场景
    • Ask
    • Features
    • QPS
    • DAU
    • Interface
  • Service 服务
    • Slipt
    • Application
    • Module
  • Storage 存储
    • Schema
    • Data
    • SQL
    • NoSQL
    • FileSystem
  • Scale
    • Sharding
    • Optimize
    • Special Case

Scenario 场景

  1. 确定需要设计哪些功能
  2. 承受多大访问量: MAU,DAU

罗列功能

Enumerate all features

QPS analsis

Average QPS: DAU * times_user_request

Peak QPS: averaeg QPS * 3

Fast Growing system: peak user * 2

Why we need QPS?

  1. QPS = O(100), your laptop can serve the QPS
  2. QPS = O(1k), a decent server
  3. QPS = O(1m), web server

Service 服务

  1. Replay 重放需求:重新过一遍需要的每个需求,为每个需求添加一个服务
  2. Merge 归并需求:归并相同的服务

Major Types:

  • User Service: Register, login
  • Tweet Service
  • Media Service
  • Friendship Service

Storage 存储

  1. 为每个Service选择存储结构
  2. Schema细化表结构

Database

  • Relationship Database: Need sharding
  • NoSQL Database: Tweets: Append, Simple Id based

File SystemDesign

  • Thumbnail, Media File

Cache

  • Nonpersistent

User Table

  • Integer: user_id
  • String: user name
  • String: email
  • String: password

Scale 拓展

  1. Optimize 优化

    • 解决设计缺陷 Solve Bottle Neck:Pull V.S. Push
    • 更多功能设计 More Features:Like,Follow
    • 一些特殊情况 Special Cases
  2. Maintainence 维护

    • 鲁棒性 Robust
    • Scalability