Sharding (Partitioning)
Split data across nodes by a shard key.
- Range (
A–F,G–M…): range scans are efficient; risk of hot ranges (e.g. timestamps). - Hash (
hash(key) % Nor consistent hashing): even spread; range queries scatter. - Directory / lookup service: flexible, extra hop.
Choosing a key: high cardinality, even access, and matching the dominant query (e.g. user_id for per-user data). Watch out for:
- Hot partitions (celebrity users) → add a random suffix / split the key, cache.
- Cross-shard queries & transactions → denormalize, scatter-gather, or 2PC/sagas.
- Resharding → consistent hashing or many logical shards mapped to fewer physical nodes.