Cassandra Primary Keys
Cassandra schemas can be a bit hard to design and are especially important to design correctly because of the distributed nature of Cassandra. Many new users of Cassandra try to design schemas similar to relational databases because of CQL’s similar syntax to SQL.
CREATE TABLE example ( key uuid PRIMARY KEY )
CREATE TABLE example ( key1 text, // partition key: determines how data is partitioned across nodes key2 int, // clustering key: determines how data is sorted within a partition PRIMARY KEY(key1, key2) )
The goals for designing cassandra keys (stolen from the datastax documentation) are:
- Spread data evenly around the cluster
- Minimize the number of partitions read