liveBook · Manning

Hash ring

As explained in ScyllaDB in Action

A hash ring is a circular partitioning structure that maps hashed keys to responsible nodes in a distributed database cluster.

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.
figure

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.
figure

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

How ScyllaDB in Action covers it

How deep it goes
Defines tokens, node-owned slices, vnodes, joining-node streaming, replication placement, and TOKEN inspection without detailing the hash algorithm.
Examples
Uses ring diagrams, vnode ownership slices, an author-ID TOKEN query, and a node-status listing.
What it assumes
Explains partition-key distribution from a high-level starting point before introducing tokens and virtual nodes.
What you can do after
Evaluate/understand how a partition key determines request routing, replica placement, and redistribution when nodes join.
How it connects
Connects partition keys, tokens, virtual nodes, replication factor, consistency levels, and eventual consistency.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ScyllaDB in Action. The section links point to the parts of the book it draws on.