Company
Date Published
Author
William Zola
Word count
2432
Language
English
Hacker News points
None

Summary

A good shard key for MongoDB should distribute inserts, updates, and deletes uniformly across all shards, and queries uniformly across all shards. A perfect shard key would also ensure that operations only target the shards of interest, and that read locality is maintained, but this may not be possible to achieve. Cardinality, write distribution, read distribution, read targeting, and read locality are key considerations when selecting a shard key. A good shard key should match the workload of the application, and tradeoffs must be made between these factors. The ideal approach is to carefully consider all operations, optimize the important ones, and ensure that other operations are reasonably efficient.