liveBook · Manning

Key hash partitioning

As explained in Latency

Key hash partitioning assigns records to partitions according to a hash of their partitioning-key values.

Key hash partitioning assigns records to horizontal partitions using a hash of their partitioning-key values. Records with the same key value go to the same partition. By spreading different key values across partitions, hashing can improve load balance and reduce hotspots and latency. section 5.2.1

Partitioning by location

If Location is the partition key, users in New York are placed together, while users in Sydney and Cape Town occupy their own partitions. The example illustrates how a logical table can be divided into horizontal partitions. section 5.2.1

Figure 5.1 Horizontally partitioning a database table. On the left, you can see the full logical table with four rows. On the right side, you can see three horizontal partitions.
Figure 5.1: Example of horizontal partitioning of a database table. At the left side of the diagram, you see the full logical table with four rows. On the right side of the diagram, you see three horizontal partitions.

Compare the logical table with its three horizontal partitions. section 5.2.1

Hashing does not guarantee balanced partition sizes. A low-cardinality key limits the number of distinct values available for distribution, and a skewed value can put many records together. For better balance, choose a high-cardinality key or combine columns to increase cardinality. Values can also differ in size: partitions holding larger images, for example, may be much larger even when key counts are equal. section 5.2.1 section 5.5.1

Choose the strategy for the access pattern and data distribution. Hashing ZIP codes can distribute unevenly populated areas better than partitioning by ZIP-code ranges. Range partitioning, however, supports range scans when keys are naturally ordered or have predictable ranges. Changing a poor partitioning scheme may require rebalancing every partition, which can be difficult on a live system. section 5.2.1 section 5.5.1

Routing a user-profile request

In a partition-aware HTTP client, a possible extension is to hash the user ID to select the node for a user-profile request. Request routing alone is not data partitioning: the client must implement a partitioning strategy to add it. section 5.6

How Latency covers it

How deep it goes
Explains key selection and imbalance trade-offs, then proposes user-ID-based routing without implementing it.
Examples
Uses location and ZIP-code distributions and proposes routing user-profile requests by user ID.
What you can do after
Evaluate and understand partition-key choices and recognize why hashing may leave partitions imbalanced.
How it connects
Connects horizontal partitioning with key range partitioning, partition-key cardinality, hotspots, range scans, and rebalancing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Latency. The section links point to the parts of the book it draws on.