系统设计面试题 - 通过分类特性设计 Amazon 的销售排名

2018-04-26  本文已影响67人  专职跑龙套

引用:
系统设计入门

通过分类特性设计 Amazon 的销售排名

解答

第一步:通过讨论,明确限制及用例,确定Scope

支持的用例:

不支持的用例:

Constraints and assumptions:

计算规模:
每笔交易:

每月:40 bytes * 1 billion = 40G

第二步:高层次设计

通过分类特性设计 Amazon 的销售排名

第三步:设计核心组件

加入交易信息遵从一下的格式,存储在 Object Store 中

timestamp   product_id  category_id    qty     total_price   seller_id    buyer_id
t1          product1    category1      2       20.00         1            1
t2          product1    category2      2       20.00         2            2
t2          product1    category2      1       10.00         2            3
t3          product2    category1      3        7.00         3            4
t4          product3    category2      7        2.00         4            5
t5          product4    category1      1        5.00         5            6
...

Service Rank Service 的主要工作:

id int NOT NULL AUTO_INCREMENT
category_id int NOT NULL
total_sold int NOT NULL
product_id int NOT NULL
PRIMARY KEY(id)
FOREIGN KEY(category_id) REFERENCES Categories(id)
FOREIGN KEY(product_id) REFERENCES Products(id)

提供一个REST 形式的 Read API 供用户查看:

第四步:扩展设计

通过分类特性设计 Amazon 的销售排名
上一篇 下一篇

猜你喜欢

热点阅读