System Design
Advanced
Partitioning and Sharding
Split data and traffic while preserving locality, fairness, and operability.
35 min
3 sections
sharding
partitioning
scale
1
2
3
01. Partition for the dominant access path
Section 1 of 3
A shard key should spread load and keep common queries local. User ID works for user-owned data. Tenant ID works for SaaS isolation but can create hot tenants. Time works for logs but can create hot current partitions.
text
Shard key comparison:
user_id:
Good for user timelines and profiles.
Bad for global analytics.
tenant_id:
Good for enterprise isolation.
Risky when one tenant is huge.
hash(order_id):
Good distribution.
Bad for listing all orders for a user.
created_month:
Good for retention and archival.
Risky for hot current-month writes.Back to Course