Cassandra Scaling Operations
This section covers horizontal scaling procedures for Cassandra clusters, including capacity planning, node addition and removal strategies, and operational best practices for maintaining cluster balance during topology changes.
Scaling Model
Section titled “Scaling Model”Horizontal vs Vertical Scaling
Section titled “Horizontal vs Vertical Scaling”Cassandra is designed for horizontal scaling—adding more nodes rather than larger nodes:
| Approach | Advantages | Disadvantages |
|---|---|---|
| Horizontal | Linear scaling, fault tolerance | Data movement required |
| Vertical | No data movement | Hardware limits, no added fault tolerance |
Capacity Planning
Section titled “Capacity Planning”Key Metrics
Section titled “Key Metrics”Before scaling, assess current cluster state:
| Metric | Target Range | Action if Exceeded |
|---|---|---|
| Disk usage | < 50% | Add nodes before 60% |
| CPU utilization | < 60% | Add nodes or optimize queries |
| Memory pressure | Heap < 80% | Tune JVM or add nodes |
| Read latency (p99) | < 50ms | Add nodes or review data model |
| Write latency (p99) | < 25ms | Add nodes or reduce batch size |
Data Distribution Formula
Section titled “Data Distribution Formula”For a cluster with N nodes and replication factor RF:
Data per node = (Total data × RF) / N
Example:- Total unique data: 1 TB- RF: 3- Nodes: 6- Data per node: (1TB × 3) / 6 = 500 GBScaling Calculations
Section titled “Scaling Calculations”Adding nodes:
New data per node = Current data per node × (N / (N + new_nodes))
Example: Adding 3 nodes to 6-node cluster- Current: 500 GB per node- New: 500 GB × (6 / 9) = 333 GB per nodeData movement estimation:
Data to stream = (Total data × RF × new_nodes) / (N + new_nodes)
Example: Adding 3 nodes- Data to stream: (1TB × 3 × 3) / 9 = 1 TB totalScaling Up (Adding Nodes)
Section titled “Scaling Up (Adding Nodes)”Planning Node Addition
Section titled “Planning Node Addition”Addition Best Practices
Section titled “Addition Best Practices”| Practice | Rationale |
|---|---|
| Add multiple of RF | Helps maintain balanced distribution (mainly for single-token deployments) |
| Add one at a time | Reduces cluster stress |
| Wait for NORMAL | Ensure complete bootstrap |
| Schedule during low traffic | Minimize impact |
| Monitor existing nodes | Watch for compaction backlog |
Vnodes vs Single-Token
With vnodes (multiple tokens per node), adding exact multiples of RF is less critical as data is distributed across many token ranges.
Multi-Datacenter Scaling
Section titled “Multi-Datacenter Scaling”When scaling across datacenters:
# Ensure proportional capacity per DC# Example: RF=3 per DC
DC1: 6 nodes (3 replicas distributed across 6)DC2: 6 nodes (3 replicas distributed across 6)
# Add 2 nodes to each DC to maintain balanceDC1: 8 nodesDC2: 8 nodesAdding Nodes Procedure
Section titled “Adding Nodes Procedure”# Step 1: Verify cluster healthnodetool status # All UN
# Step 2: Configure new node# cassandra.yaml with cluster settings# Ensure same cluster_name, seeds, snitch
# Step 3: Start new nodesudo systemctl start cassandra
# Step 4: Monitor bootstrapwatch -n 5 'nodetool netstats'
# Step 5: Wait for completion (status shows UN)nodetool status
# Step 6: Run repair on new nodenodetool repair -pr
# Step 7: (If adding multiple) Repeat for next nodevnodes and Token Distribution
Section titled “vnodes and Token Distribution”With vnodes (recommended), token allocation is automatic:
num_tokens: 16 # Default, provides good distribution
# Optional: Allocate tokens for specific keyspaceallocate_tokens_for_keyspace: my_keyspacevnodes advantages:
- Automatic token allocation
- Better load distribution
- Faster streaming (parallel)
- Easier operations
Scaling Down (Removing Nodes)
Section titled “Scaling Down (Removing Nodes)”Planning Node Removal
Section titled “Planning Node Removal”Removal Constraints
Section titled “Removal Constraints”Before removing nodes, verify:
| Constraint | Check | Consequence if Violated |
|---|---|---|
| RF satisfied | Nodes remaining ≥ RF | Decommission blocked |
| Disk capacity | Remaining nodes have space | Disk full errors |
| Performance | Load can be handled | Latency increase |
Removing Nodes Procedure
Section titled “Removing Nodes Procedure”# Step 1: Verify remaining capacity# Calculate new disk usage per node
# Step 2: Check RF requirementsnodetool describering <keyspace>
# Step 3: On node being removed, run decommissionnodetool decommission
# This:# - Streams all data to remaining nodes# - Takes significant time (hours for large datasets)# - Can be cancelled with nodetool abortdecommission
# Step 4: Monitor progresswatch -n 10 'nodetool netstats'
# Step 5: Verify completionnodetool status# Removed node should no longer appear
# Step 6: Update seed list if node was a seed# Edit cassandra.yaml on all nodes# Rolling restart (optional but recommended)Rebalancing
Section titled “Rebalancing”When Rebalancing is Needed
Section titled “When Rebalancing is Needed”Token rebalancing may be necessary when:
- Historical uneven additions created imbalance
- Single-token clusters need redistribution
- Significant data skew exists
Rebalancing with vnodes
Section titled “Rebalancing with vnodes”With vnodes, adding/removing nodes automatically rebalances. Manual intervention is rarely needed.
Detecting Imbalance
Section titled “Detecting Imbalance”# Check data distributionnodetool status
# Look for significant variation in "Load" column# Example of imbalanced cluster:# UN 10.0.1.1 500 GB ...# UN 10.0.1.2 800 GB ... # 60% more data# UN 10.0.1.3 450 GB ...
# Check token ownershipnodetool ringAddressing Imbalance
Section titled “Addressing Imbalance”| Imbalance Cause | Solution |
|---|---|
| Partition key hotspot | Review data model |
| Token distribution | Add nodes (vnodes auto-balance) |
| Uneven node specs | Standardize hardware |
Scaling Strategies
Section titled “Scaling Strategies”Double the Cluster
Section titled “Double the Cluster”Adding nodes equal to current count provides optimal rebalancing:
Initial: 3 nodes, 1TB eachAdd: 3 nodesResult: 6 nodes, 500GB each
Data movement: 50% of data moves (optimal)Incremental Addition
Section titled “Incremental Addition”Adding fewer nodes is possible but less efficient:
Initial: 3 nodes, 1TB eachAdd: 1 nodeResult: 4 nodes, 750GB each
Data movement: 25% of data movesNew node load: May still be uneven with vnodesMulti-Region Scaling
Section titled “Multi-Region Scaling”Guidelines:
- Scale regions proportionally
- Maintain RF per region
- Consider latency requirements
Streaming Impact
Section titled “Streaming Impact”During Scale-Up
Section titled “During Scale-Up”Adding nodes creates streaming load:
| Impact | Mitigation |
|---|---|
| Network bandwidth | Throttle with stream_throughput_outbound_megabits_per_sec |
| Disk I/O | Schedule during low-traffic hours |
| CPU (compaction) | Monitor pending compactions |
| Memory | Ensure heap headroom |
# cassandra.yaml - Streaming throttle# 4.1+ format (data rate)stream_throughput_outbound: 200MiB/sinter_dc_stream_throughput_outbound: 50MiB/s
# Pre-4.1 format# stream_throughput_outbound_megabits_per_sec: 200# inter_dc_stream_throughput_outbound_megabits_per_sec: 50During Scale-Down
Section titled “During Scale-Down”Decommissioning creates similar streaming load, plus:
- Remaining nodes receive additional data
- Compaction increases post-streaming
Operational Checklist
Section titled “Operational Checklist”Before Scaling
Section titled “Before Scaling”- Current cluster health (all nodes UN)
- No pending repairs or streaming
- Disk usage < 50% on all nodes
- Network bandwidth available for streaming
- Maintenance window scheduled
- Backups current (if applicable)
During Scaling
Section titled “During Scaling”- One node at a time
- Monitor streaming progress
- Watch for errors in logs
- Track compaction backlog
- Verify each node reaches NORMAL
After Scaling
Section titled “After Scaling”- All nodes show UN status
- Data distribution is balanced
- Performance metrics nominal
- Repair completed on new nodes
- Seed list updated (if applicable)
- Documentation updated
Monitoring During Scaling
Section titled “Monitoring During Scaling”Key Metrics to Watch
Section titled “Key Metrics to Watch”# Streaming progressnodetool netstats
# Compaction statusnodetool compactionstats
# Thread pool statusnodetool tpstats
# Overall statusnodetool statusAlert Thresholds During Scaling
Section titled “Alert Thresholds During Scaling”| Metric | Warning | Critical |
|---|---|---|
| Streaming stuck | No progress for 30 min | No progress for 1 hour |
| Pending compactions | > 50 | > 100 |
| Dropped messages | > 0.1% | > 1% |
| Disk usage | > 70% | > 80% |
Related Documentation
Section titled “Related Documentation”- Node Lifecycle - Bootstrap and decommission details
- Data Streaming - Streaming mechanics
- Partitioning - Token distribution
- Seeds and Discovery - Seed management during scaling