A hash ring is a circular data-distribution structure. It maps a table’s partition key through a hash function to an integer token, then uses that token to determine which cluster node owns the partition. Rows sharing a partition key map to the same place; different keys almost always map elsewhere. section 3.3.1
Figure 3.8 Partitions are mapped to places on a hash ring.
The ring visualizes the first step: a partition key becomes a token and is placed at a position around the circle. section 3.3.1
Nodes claim slices of the ring. A node usually joins at many positions, creating virtual nodes, or vnodes. Each vnode owns the data in its slice until the next node position. Splitting ownership into many smaller slices makes redistribution easier to parallelize when a node joins. section 3.3.1
The ring drives several cluster operations:
- Route reads and writes: hash the partition key, find its token, and forward the request to the owning node. section 8.2.1
- Add capacity: a joining node takes over portions of existing slices, and previous owners stream the affected data to it. section 3.3.1
- Replicate partitions: assign copies to subsequent eligible nodes on the ring until the replication factor is met. section 8.2.1
- Inspect placement: use the CQL TOKEN function to view the token associated with a partition-key value. section 8.2.1
Finding an author partition’s token
A query such as SELECT TOKEN(id), id FROM reviews.authors; returns each author ID with its token. The token identifies where that partition falls on the ring; ScyllaDB uses the same partition-key hashing idea to locate the owning node for reads and inserts. section 8.2.1
The hash ring is central to a peer-based cluster: any contacted node can calculate where a row belongs and forward the request without relying on a leader. Together with replication factor and consistency choices, this distribution supports scalability and availability, while allowing eventual consistency. section 1.2.1 section 8.2.1
Figure 3.10 Each node joins the ring in multiple places as vnodes, making the slices of the ring smaller and easier to manage.
Multiple vnode positions per node divide ownership into smaller slices, so data handoffs can be spread across the cluster rather than performed as one large transfer. section 3.3.1
