九章算法-系统设计#6 网站设计

How to Scale

Single Point Failure

  1. 数据拆分 Sharing (Partition): 按照一定的规则,将数据拆分存储在不同的实体机器上
    1. 挂了一台不会全挂
    2. 分摊读写流量
  2. 数据复制 Replica
    1. 一台机器挂了可以用其他两台的数据恢复
    2. 分摊读请求

数据Sharding

  1. 纵向拆分 Vertical Sharding: User Table 放一台数据库, Friendship Table 放一台数据库, Message Table 放一台数据库
  2. 横向拆分 Horizontal Sharding (more important)

Hashing

一致性哈希算法 Consistent

哈希函数 Hash Function: 将任意类型的 key 转换为一个 0~size-1 的整数。在 Consistent Hashing 中,一般取 size = 2^64