按一个几乎出现在每次查询中且能均匀分散负载的键分片——通常是哈希后的 user_id——然后从第一天起就为重新分片(resharding)和跨 shard 查询做规划。10 亿用户在单个节点上装不下也跑不动;你把行拆分到许多数据库上,并把每次查询路由到拥有它的 shard。
┌──────────────┐
Request ─▶ Router/│ shard_of(key)│─▶ Shard 0 (users 0–…)
Proxy └──────────────┘ Shard 1
(Vitess) │ Shard 2
└─────────▶ Shard N ← each = its own primary+replicas
Directory/lookup table (which key → which shard) ── for range or resharding
Shard key 选择——难以撤销的决策
选一个的键。 通常胜出:以用户为范围的查询("我的资料、我的订单")恰好命中一个 shard。糟糕的键(例如 )会造成热点——一个 shard 装下整个印度,而另一个闲置。
