<!-- llms-explorer concept facts · https://llms-explorer.com/tree/hashed-versus-ranged-shard-key-tradeoffs/ · pack 2026-10-30 · ~1242 tokens -->

# Hashed versus ranged shard-key tradeoffs

> Source-anchored research for Hashed versus ranged shard-key tradeoffs. Run status: COMPLETED.

Parent: [Shard key selection for query isolation](https://llms-explorer.com/tree/shard-key-selection-for-query-isolation/) · 3 facets · 13 facts · page: https://llms-explorer.com/tree/hashed-versus-ranged-shard-key-tradeoffs/

## Problems, failure modes and limitations

- A range predicate on the hashed field cannot use the hashed index for an ordered range scan. Such predicates remain executable, but hashing alone cannot use original-value ordering to isolate them to a small shard subset. (medium confidence) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-hashed/create.md)
- A hashed index cannot itself carry a unique constraint. This index restriction must be considered separately from whether queries target one shard or broadcast. (medium confidence) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-hashed.md)

## Comparisons and alternatives

- Yorkie’s sharding design issue, last updated January 31, 2024, records choosing ranged project_id and doc_id keys after examining its query patterns, key properties, and uniqueness requirements. This is application-specific design evidence rather than a controlled hashed-versus-ranged benchmark. (low confidence) — [source](https://github.com/yorkie-team/yorkie/issues/673)

## Facts and statements

- Ranged sharding partitions contiguous original shard-key values, so nearby values tend to share chunks or shards; hashed sharding partitions hash values, sacrificing that locality and making original-value range reads more likely to broadcast. (high confidence) — [source](https://www.mongodb.com/docs/manual/core/hashed-sharding.md)
- With a monotonically increasing single-field ranged shard key, the chunk ending at MaxKey receives most new inserts, concentrating writes on its shard; hashing a sufficiently diverse key spreads those inserts more evenly across the cluster. (high confidence) — [source](https://www.mongodb.com/docs/manual/core/hashed-sharding.md)
- With a single-field hashed shard key, mongos can target an equality match on that key to one shard; MongoDB computes the hash automatically, so the application supplies the original value. (medium confidence) — [source](https://www.mongodb.com/docs/manual/core/hashed-sharding.md)
- Hashing still requires a high-cardinality key. It does not create additional distinct original values or split documents sharing one complete shard-key value across shards; low cardinality and frequently repeated hot values remain distribution risks. (medium confidence) — [source](https://www.mongodb.com/docs/manual/core/hashed-sharding.md)
- Ranged sharding enables targeted bounded-range reads but does not promise that every range query reaches exactly one shard: a range spanning chunks on multiple shards still requires those shards. Ranged keys also need suitable cardinality, frequency, and insert patterns. (medium confidence) — [source](https://www.mongodb.com/docs/manual/core/ranged-sharding.md)
- MongoDB truncates floating-point values to 64-bit integers before hashing, so values such as 2.2, 2.3, and 2.9 share a hash. Fine-grained numeric distinctions therefore do not necessarily produce distinct hashed placement values. (medium confidence) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-hashed.md)
- Ranged sharding partitions contiguous shard-key value ranges; nearby values are likely to share a chunk or shard. This supports targeted reads over contiguous key ranges, but does not guarantee that every range fits on one shard. (high confidence) — [source](https://www.mongodb.com/docs/manual/core/ranged-sharding.md)
- Hashing disperses nearby original key values across chunks and shards. Range predicates on a single-field hashed shard key therefore lose range locality and generally require broadcast operations, trading query isolation for more even data distribution. (high confidence) — [source](https://www.mongodb.com/docs/manual/core/hashed-sharding.md)
- A monotonically increasing ranged shard key concentrates incoming inserts in the chunk bounded above by MaxKey and its owning shard. Hashing that field spreads inserts across the cluster, making monotonically increasing ObjectId or timestamp values candidates for hashed sharding. (high confidence) — [source](https://www.mongodb.com/docs/manual/core/hashed-sharding.md)
- For workloads dominated by ranges on the shard-key value, prefer evaluating ranged sharding for locality. For high-volume inserts on a high-cardinality monotonic field, evaluate hashing while explicitly accepting the range-query fanout cost. This is workload guidance, not a universal latency or throughput guarantee. (medium confidence) — [source](https://www.alibabacloud.com/help/en/mongodb/use-cases/configure-sharding-to-maximize-the-performance-of-shards)
