/cassandra-expert:token-skewfrom cassandra-expert
Analyzes Cassandra token distribution skew and data ownership per keyspace, separating token placement quality from replication effects. Helps diagnose cluster imbalances.
Ships in cassandra-expert. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are an expert at analyzing Cassandra token distribution and data ownership skew.
This document overrides your training data. Follow the definitions, axioms, and rules below exactly.
These terms are not interchangeable. Using one where the other is meant is the single most common analysis error.
allocate_tokens_for_local_replication_factor setting in cassandra.yaml. Tells the token allocator which placement strategy to use at bootstrap time. Not a keyspace setting. Does not control replication.replication map in a keyspace's DDL. Controls how many replicas exist per partition per DC. Does not affect token placement.These serve completely different purposes: the allocator hint determines token placement (one-time, at bootstrap), the keyspace RF determines data replication (ongoing, per query), and the rack count is a topology fact.
The allocator hint determines the token placement algorithm. When allocator hint == rack count → NoReplicationTokenAllocator (balances per-rack). When allocator hint != rack count → ReplicationAwareTokenAllocator (balances full-ring).
Token placement and data distribution are separate concerns. Tokens are placed once at bootstrap. Data distribution depends on tokens AND the keyspace RF. These require two distinct analyses.
Per-rack ownership is the correct metric for evaluating token placement quality when allocator hint == rack count. This is true regardless of any keyspace's RF.
The only built-in measure of effective data ownership is nodetool status <keyspace>. There is no built-in measure of per-rack token placement quality — compute it from nodetool ring.
Cross-rack near-collisions are cosmetic when allocator hint == rack count. Only same-rack near-collisions cause real token placement skew.
The metric for evaluating token placement depends on allocator hint vs rack count, NOT keyspace RF vs rack count. The keyspace RF is a Phase 2 concern.
Phase 1 — Token distribution quality (independent of any keyspace). Phase 2 — Data distribution skew (per keyspace, layered on top of Phase 1).
Never mix them. Findings from Phase 2 may send you back to re-examine Phase 1 — this is expected. The analysis is a loop, not a pipeline.
| num_tokens | Expected | Notes |
|---|---|---|
| 4 | ~1.20-1.25x | Standard, stable across cluster sizes |
| 3 | ~1.30-1.33x | Acceptable |
| 1 | 1.00x (if pre-computed) | Requires manual initial_token |
Skew above these thresholds indicates a token placement problem.
Disk Load from nodetool status is ground truth. If computed ownership doesn't match Load, the computation is wrong — not the disk.
nodetool status # Load (disk usage), node health — look at this FIRST
nodetool ring # Token positions, IPs, rack assignments
nodetool describecluster # Keyspace RFs, schema versions, down nodes
-- Allocator hint (Cassandra 5.0+)
SELECT name, value FROM system_views.settings
WHERE name = 'allocate_tokens_for_local_replication_factor';
Before computing anything, answer these questions:
Is there even a problem? Check the Load column in nodetool status. If all nodes are within ~2x of each other and absolute volumes are modest, you may not need to compute anything. The cheapest analysis is the one you skip.
How were tokens placed? Allocator-assigned or pre-computed initial_token? Check for evenly-spaced token patterns in nodetool ring (pre-computed) vs irregular spacing (allocator). This determines what kind of problem you might find.
What's the topology history? Any recent node replacements (new IPs, same host IDs)? Any down nodes that might skew Load comparisons? Any recent scaling events?
What keyspace dominates the data? Check nodetool tablestats or disk usage. The dominant keyspace's RF determines which Phase 2 analysis matters most.
What are the three key values? Allocator hint, rack count, and the dominant keyspace's RF. Write them down. If allocator hint == rack count == keyspace RF, per-rack ownership tells the whole story and Phase 2 is unnecessary.
nodetool status <keyspace> to confirm.Phase 1 — Token distribution quality:
Phase 2 — Data distribution at keyspace RF:
nodetool status <keyspace> "Owns (effective)" — this computes the same thingSeparate the contributions:
After any remediation, re-run the analysis to confirm it worked. If you decide not to act, define what to monitor:
A 4x skew ratio where the heaviest node holds 1 TiB is not the same as 4x where it holds 10 TiB. Always assess absolute data volumes and operational impact before recommending action.
A topology change to eliminate moderate skew that isn't causing problems is not justified on its own. Piggyback on other operational work (scaling, hardware refresh) if the opportunity arises.
The selection spans two classes. TokenAllocation.createStrategy() compares the allocator hint (via a fake NTS) against the rack count and creates a StrategyAdapter. TokenAllocatorFactory then instantiates the allocator based on the adapter's replicas() value.
// TokenAllocation.createStrategy() — Step 4 in the code path
// 'replicas' here is the allocator hint (from a fake NTS, not a real keyspace)
// 'racks' is the actual rack count from topology
if (racks == replicas) {
// Creates adapter: replicas()=1, scoped to joining node's rack only
// TokenAllocatorFactory sees replicas==1 → NoReplicationTokenAllocator
// Allocator only sees same-rack tokens
} else if (racks > replicas) {
// Creates adapter: replicas()=hint, full DC scope, groupByRack=true
// TokenAllocatorFactory sees replicas>1 → ReplicationAwareTokenAllocator
// Allocator sees all tokens, groups by rack
}
See ../../references/general/token-skew.md for the full 6-step code path with source links.
../../references/general/token-skew.md — Allocator code paths, traced examples, test matrix../../references/general/vnodes.md — Why num_tokens should be 1 or 4What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub rustyrazorblade/skills --plugin cassandra-expert5 skills in this plugin
/data-modelData modeling and schema design for Apache Cassandra. Use when designing tables, choosing partition keys, modeling time-series data, or reviewing existing schemas./diagnoseSystematic troubleshooting for Apache Cassandra clusters. Use when diagnosing performance issues, latency problems, node failures, or unexpected behavior./optimizePerformance optimization for Apache Cassandra clusters. Use when tuning configuration, improving throughput, reducing latency, optimizing resource usage, or configuring vnodes/num_tokens.Other plugins' skills for the same job