LESSON 01 · Placement contract

Know what the mapping must preserve

A partition function assigns each key to an owner and determines how much data moves when capacity changes.

SYSTEM VIEW

The placement map

Diagram view
Node C’s keys—
Node C’s reads—

Watch app servers hash keys to four cache nodes, then see equal key counts hide very unequal work.

  1. A cache spreads its keys over four nodes. To read user:7, an app server runs a placement function: it hashes the key, gets Node B, and asks Node B directly. No central service is asked; Memcached clients work this way, and its servers don’t know about each other.

    Rule
    hash(key) → node
    Asks
    no central service

    What changed

    • user:7 → Node B
    • Clients decide, not a service
  2. The rule gives one answer only if every app server holds the same membership view, the current list of nodes: A, B, C, D. It should also move few keys when that list changes, since a moved cache entry costs a miss and a moved durable partition a bulk copy.

    Members
    A, B, C, D
    Moved cache key
    one miss
    Moved partition
    a bulk copy

    What changed

    • One membership view
    • Goal: few keys move
  3. Hashing makes key positions look uniform, so of the cache’s 100 million keys each node holds 25 million. With ordinary traffic each node also serves a quarter of the reads. By key count, the placement is balanced.

    Keys
    100 million
    Per node
    25 million

    What changed

    • 25 million keys per node
    • Reads spread evenly
  4. A viral post makes 1,000 keys on Node C draw 30% of all requests. The other 70% spreads evenly, 17.5% per node, so Node C serves 47.5% while the rest serve 17.5% each. Every node still holds 25 million keys.

    Viral keys
    1,000 on Node C
    Node C
    30% + 17.5% = 47.5%
    Keys per node
    still 25 million

    What changed

    • 1,000 viral keys draw 30%
    • Node C serves 47.5%
    • Others serve 17.5% each
  5. Key count alone called this cluster balanced. Monitoring that also tracks bytes and request rate on every node shows Node C at 47.5% of reads. Hot keys skew requests, and a few very large values can skew memory the same way.

    Watch
    keys · bytes · req/s
    Node C
    25% keys, 47.5% reads

    What changed

    • Monitoring per node
    • Keys even, reads skewed
  6. Node B fails, and the function still sends user:7 to Node B. Placement copies no data, detects no failure and guarantees no availability; replicas and failure detection do that. And if one machine with a standby can hold your data, you may not need placement at all.

    What changed

    • Node B fails
    • user:7 still goes to Node B

Space plays · ← → step · Home resets

THE IDEA

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.

DECISION POINT

A cluster has equally many keys per node, yet one node uses twice the CPU. What does this tell you?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • State the remapping and balance goals before choosing a hash scheme.
  • Key count, bytes, and request heat are different balancing targets.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
RecallQUESTION 01

What does a placement function decide?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.