The idea: every node knows a few others, and that is enough
A distributed hash table (DHT) stores key-value pairs on many machines with no central
index. Given a key, any machine must find the machine that holds it. Chord (Stoica et al.,
2001) answers that with one operation, find_successor(id). Nodes and keys get ids on the same
identifier ring of 2m ids (a hash such as SHA-1 picks them; the page uses m = 6,
ids 0 to 63). A key lives at its successor: the first node at or after the key, going
clockwise. K54 lives at N56, and K24 and K30 both live at N32.
The page uses the ten nodes of the paper's own example. How keys are hashed onto a ring, and why adding a node moves only one arc of keys, is the subject of Consistent Hashing. There every server knows the whole ring. Chord is for the case where nobody does: each node knows only O(log N) others, and the lookup is routed from node to node.
Walking the ring: O(N)
The simplest rule: every node knows its successor. A node that does not hold the key passes the query on to its successor. In Demo 1: key 54 from N8, successors only the query goes 8 → 14 → 21 → 32 → 38 → 42 → 48 → 51. N51 sees that 54 lies in (51, 56], between itself and its successor, so N56 is the answer, and N51 sends it back to N8. That is 7 hops and 8 messages. With N nodes a lookup takes up to N − 1 hops; on the page the average over all 10 nodes and 5 keys is 4.5 hops.
Finger tables: O(log N)
Each node n keeps a finger table of m entries. Entry i starts at
finger[i].start = n + 2i−1 (mod 2m) and points to
finger[i] = successor(start). So the fingers point 1, 2, 4, 8, 16 and 32 ids ahead. N8's
starts are 9, 10, 12, 16, 24, 40, and its fingers are N14, N14, N14, N21, N32, N42. finger[1] is the
successor.
| i | start = 8 + 2i−1 | finger[i] of N8 |
|---|---|---|
| 1 | 9 | N14 |
| 2 | 10 | N14 |
| 3 | 12 | N14 |
| 4 | 16 | N21 |
| 5 | 24 | N32 |
| 6 | 40 | N42 |
To route, a node calls closest_preceding_finger(id): it scans its table from finger[6]
down and takes the first finger that lies strictly between itself and the key. That finger gets as close
to the key as possible without passing it. In Demo 2 N8 sends the query for 54 to N42
(finger[6]). N42's finger[4] is N51, the last one before 54, so N42 forwards to N51, and N51 answers N56:
2 hops, 3 messages. The ids left to the key fall 46 → 12 → 3.
Why it is fast: if the key is d ids away, some finger points at least d/2 ahead without passing it, so each hop at least halves the distance. After m hops nothing is left; with N nodes spread evenly, about log2 N hops suffice. On the page the average over all nodes and keys is 1.48 hops, and the most is 3.
Joining: join, stabilize, notify
A new node only has to know one node already in the ring. In Demo 3 N26 calls
join(N8): it sets predecessor = nil and asks N8 for find_successor(26). N8
forwards to N21, and N21 answers N32. Now N26 knows its successor, but nobody knows N26.
Every node runs stabilize() from time to time. It asks its successor for its predecessor x.
If x lies between the node and its successor, x becomes the new successor. Then the node calls
notify(n) on its successor: "I think I am your predecessor". The successor accepts if its
predecessor is nil or n lies between its predecessor and itself. The page runs these in rounds, every node
once, in id order:
- Round 1: N26 asks N32 and hears "predecessor = N21". N21 is not between 26 and 32, so N26 keeps N32. It notifies N32; 26 lies in (21, 32), so N32 sets predecessor = N26. N32 now hands over the keys that are no longer in (26, 32]: K24 moves to N26, and K30 stays.
- Round 2: N21 asks N32 and hears "predecessor = N26". 26 lies in (21, 32), so N21 takes N26 as its successor and notifies it; N26 sets predecessor = N21.
- Round 3: nothing changes. The ring is correct again.
A lookup that runs in the middle can go wrong. In Demo 4, after round 1, N21 still points to N32, so a lookup for 24 ends at N32. But K24 has already moved to N26, so the lookup misses. The paper says the same: while a join is in progress a lookup may fail, and the application retries after a pause. After round 2 the same lookup reaches N26 and finds K24.
fix_fingers and stale fingers
Stabilize fixes successors and predecessors only. Fingers elsewhere still point past N26: N8's finger[5]
(start 24), N14's finger[4] (start 22), N21's finger[2] and finger[3] (starts 23 and 25) and N56's
finger[6] (start 24) all say N32 where the answer is now N26. The page marks them "stale". They do not make
lookups wrong, only a little longer, because the last steps always use correct successors.
fix_fingers() refreshes a finger with find_successor(finger[i].start). In
Demo 5 one round changes 10 fingers: those 5, plus N26's own empty fingers, which become N32, N32,
N38, N42 and N1. (The paper refreshes one random finger per call; the page does all of them in one
round.)
Failures and the successor list
A node can crash without a word. Its neighbours find out only when a message gets no answer, after a timeout. If a node knew only one successor, one crash would break the ring. So each node keeps a successor list of its r nearest successors (r = 3 on the page; the paper suggests about 2 log2 N). In Demo 6 N51 is down. N8 sends the query for 54 to N42. N42's best finger is N51: timeout. N42 marks N51 dead and uses the next finger, N48. N48's successor is N51: timeout again. N48 skips to the next entry of its successor list, N56, and 54 lies in (48, 56]. The answer is still N56, after 2 hops and 2 timeouts.
In Demo 7 one stabilize round repairs the ring: N48 drops N51 and takes N56 as successor, and N56 finds its predecessor N51 dead, clears it and accepts N48. fix_fingers then moves N42's finger[4] and N48's finger[2] from N51 to N56. Keys held only by a failed node are lost; real systems store each key on the next few successors too.
Chord and Kademlia
Both route a lookup in O(log N) hops with O(log N) contacts per node. Chord measures distance clockwise on the ring and keeps one finger per power of two. Kademlia, used by BitTorrent, measures distance with XOR, so the distance is symmetric, and it keeps several contacts per range: see BitTorrent and the Kademlia DHT. For another way a group of nodes keeps up with who is alive, see Gossip and SWIM.
What the page leaves out
- Real ids are 160-bit SHA-1 hashes, and nodes run stabilize and fix_fingers on timers, not in rounds.
- The paper's iterative form, where the asker contacts each hop itself; the page uses the recursive form.
- Replicating keys on the successor list, virtual nodes for balance, and voluntary leaves that hand keys over.
- The proofs: correctness under concurrent joins, and the O(log² N) cost of a join.