Part 4 of 6 · 2 min read
Why key-value data partitions easily
Since every access names an exact key, a request can be routed straight to the one node responsible for that key.
Think of a large postal sorting warehouse. Letters are split across many trucks, each truck responsible for a fixed range of postal codes. A sorter never has to check every truck. The postal code alone says exactly which truck to use.
In plain words: a key-value store can split its keys across many machines, a technique called partitioning. Because every access names an exact key, the system can decide, from the key alone, exactly which machine holds that key's data. One common method hashes the key and assigns a range of hash values to each machine. Another method assigns a range of the keys themselves to each machine. Either way, a request is routed directly to the one responsible machine. Ten machines, each holding a fair share, can together handle roughly ten times the data and the read-and-write load of one machine.
A worked example. The bookstore's cart store is split across four machines. Each machine owns a quarter of the possible hash values. A request for cart:501 hashes the key, finds it falls in machine 3's range, and is sent only to machine 3. The other three machines are never contacted for this request.
The key lines. No SQL; this is an internal routing decision inside the key-value store, not something expressed in a client call.
hash("cart:501") -> falls in machine 3's assigned range
route request to machine 3 only
Partitioning (by key)
Partitioning is splitting a dataset across several machines, with each machine responsible for a defined share of the keys. Because a key-value lookup always names an exact key, a request can be routed directly to the one machine responsible for it, without contacting any other machine.
Example: a postal sorting warehouse routing each letter to one truck by postal code alone, with no need to check every truck, mirrors partitioning routing a key-value request to one responsible machine.