How it works
A distributed cache or key-value store needs a repeatable way to find the node that owns a key. A placement function is that rule: given a key, it names an owner without asking a central service on every request. Memcached is a clear example, since its servers do not know about each other and clients choose a server by hashing the key. Start with the desired properties: balanced load, predictable lookup, little movement as nodes join or leave, and a membership view (the current list of nodes) that clients can agree on.
The keys may represent cached objects, durable partitions, or routing entries, and each has a different cost of remapping. A moved cache entry costs one miss. A moved durable partition costs a bulk copy.
Hashing makes a key position look uniform, but uniform key counts do not imply uniform work. Take an example cache with four nodes and 100 million keys, 25 million on each. A viral post makes 1,000 keys on one node draw 30% of all requests. The other 70% spreads evenly, 17.5% per node, so that node serves 47.5% of traffic while the rest serve 17.5% each. A few very large values can do the same to memory. Measure bytes and request rate as well as key count. The placement method does not copy data, detect failure, or guarantee availability by itself, and if one machine with a standby can hold your data, you may not need one at all.
A cluster has equally many keys per node, yet one node uses twice the CPU. What does this tell you?
Placement may be balanced by key count while traffic is skewed. Inspect hot keys, value sizes, and operation costs before adding hash positions.
Use this as a guide for self review; written answers are not graded.Keep in mind
- State the remapping and balance goals before choosing a hash scheme.
- Key count, bytes, and request heat are different balancing targets.