Try
↑ ↓ move↵ openesc close

Interview prep / Partitioning

Junior · Partitioning · System design interview question

Why are range queries expensive under hash partitioning?

Sketch your own answer first, then compare it with the one below.

A strong answer

A range query asks for all keys between two bounds. Under hash partitioning, those keys have unrelated hashes, so they are spread over all the partitions. The query has to be sent to every partition that might hold a match, usually all of them, and the results merged.

The cost is the fan-out, since latency is set by the slowest partition, and the total work is multiplied by the number of partitions. Under range partitioning the same query touches one or two partitions.

Single-key lookups are unaffected. Some stores keep scans affordable by hashing only a prefix of the key and sorting by the rest, so a scan within one prefix stays on one partition.

Sources

Learn it by running it

The partitioning lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms