🦀 ClawHub
Cassandra
by @ivangdavila
Design Cassandra tables, write efficient queries, and avoid distributed database pitfalls.
TERMINAL
clawhub install cassandra📖 About This Skill
name: Cassandra description: Design Cassandra tables, write efficient queries, and avoid distributed database pitfalls. metadata: {"clawdbot":{"emoji":"👁️","requires":{"anyBins":["cqlsh","nodetool"]},"os":["linux","darwin","win32"]}}
Data Modeling Mistakes
Primary Key Traps
PRIMARY KEY (a, b, c): a is partition key, b and c are clustering columnsPRIMARY KEY ((a, b), c): (a, b) together is partition key—compound partition keyQuery Restrictions
WHERE must include full partition key—partial partition key fails unless ALLOW FILTERINGALLOW FILTERING scans all nodes—never use in production; redesign table insteadWHERE a = ? AND b > ? works, WHERE a = ? AND c > ? doesn'tIN on partition key hits multiple nodes—expensive; prefer single partition queriesConsistency Levels
QUORUM for most operations—majority of replicas; balances consistency and availabilityLOCAL_QUORUM for multi-datacenter—avoids cross-DC latencyONE for pure availability—may read stale data; fine for caches, bad for critical readsQUORUM + QUORUM safeTombstones (Silent Performance Killer)
nodetool cfstats -H table—Tombstone columns show problemBatch Misuse
Anti-Patterns
SELECT *—always list columns; schema changes break queriesLightweight Transactions
IF NOT EXISTS / IF column = ?—uses Paxos, 4x slower than normal writeSERIAL or LOCAL_SERIAL[applied] boolean—must check if operation succeededCollections and Counters
Compaction Strategies
SizeTieredCompactionStrategy (default)—good for write-heavy, uses more disk spaceLeveledCompactionStrategy—better read latency, higher write amplificationTimeWindowCompactionStrategy—for time-series with TTL; reduces tombstone overheadOperations
nodetool repair regularly—inconsistencies accumulate without repairnodetool status shows cluster health—UN (Up Normal) is good, DN is downnodetool describecluster to show agreement