Try
↑ ↓ move↵ openesc close

Interview prep / Partitioning

Junior · Partitioning · System design interview question

What is the difference between range partitioning and hash partitioning?

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

A strong answer

Range partitioning sorts the keys and gives each partition a contiguous stretch of the order. Hash partitioning applies a hash function to the key and uses the result to choose the partition.

Range keeps neighbouring keys together, so a scan over a key range reads from one or two partitions. It can create hot spots when traffic follows the key order, as with timestamps. Hash scatters neighbouring keys, which spreads that kind of traffic evenly, but a scan has to ask many or all partitions.

Rule of thumb: hash when lookups by exact key dominate and even load matters, range when ordered scans matter and the hot ends can be managed.

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