← Lessons

quiz vs the machine

Gold1340

Databases

Cassandra Ring and Tokens

How Cassandra distributes data across nodes with a token ring.

5 min read · core · beat Gold to climb

A peer to peer ring

Cassandra has no leader node. Every node is equal and arranged logically in a ring. There is no single point of failure and any node can accept a request as a coordinator.

Tokens

The ring is a range of token values. Each node owns one or more token ranges.

  • The partition key of a row is hashed with a partitioner such as Murmur3.
  • The resulting token decides which node owns the row.

Virtual nodes

Early Cassandra gave each node one large range, which made rebalancing uneven. Virtual nodes (vnodes) split each physical node into many small ranges scattered around the ring.

  • Vnodes spread data and streaming work evenly.
  • Adding or removing a node rebalances in smaller, parallel chunks.

The coordinator

The node a client connects to acts as the coordinator. It uses the token to find which nodes own the data and forwards the read or write to them.

Diagram

Key idea

Cassandra hashes the partition key to a token and the ring maps that token to the node that owns the data, with vnodes keeping ownership balanced.

Check yourself

Answer to earn rating on the learn ladder.

1. What determines which node owns a row in Cassandra?

2. What problem do virtual nodes solve?