Distributing partition tokens

When Cassandra distributes data, it assigns each node a range of tokens; a row is stored on the node within whose token range its partition key token falls. Since tokens are generated using a hashing function, token values are distributed evenly across the entire range of possible values. So, as long as the number of partition keys is much bigger than the number of nodes in the cluster, partition keys will be balanced evenly between the different nodes if each node is responsible for an equally sized portion of the token range.

Let's take a look at a few rows in our users table and examine how they would be distributed in a three-node cluster:

SELECT "username", TOKEN("username") FROM "users" WHERE "username" ...

Get Learning Apache Cassandra - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.