Terminal
Terminal/Skill
Guidance on when to shard an Azure DocumentDB collection, choosing a shard key, and fixing uneven load across physical shards.
By Microsoft
Works with
npx skills add azure/documentdb-agent-kit --skill documentdb-shardingAzure DocumentDB shards collections horizontally by hashing a shard key from each document and bucketing documents into logical shards, which the service then maps onto physical shards (the actual nodes that store data and serve traffic). The service hides the placement: you pick a shard key, the service handles the hash range and rebalancing.
The decisions that you own:
sh.reshardCollection), but only at significant cost once the collection is large.sh.shardCollection / db.adminCommand({ shardCollection: "db.collection", key: {...} }), sh.reshardCollection, and the requirement to create an explicit index on the shard key (with enableLargeIndexKeys: true).collection's expected size or throughput ≤ one physical shard's budget?
├─ yes → leave unsharded. Scale up if needed.
└─ no → shard.
├─ read-heavy? → key = most frequent query filter
└─ write-heavy? → key = highest-cardinality, evenly distributed field
indexing/ (index on the shard key), query-optimization/ (single-shard vs scatter-gather queries), high-availability/ (replica sets within each physical shard)