Search code examples
cassandracassandra-3.0cassandra-2.0

Primary Key in Cassandra


I have the following scenario;

My data has the id field, and this field constantly increasing.

When event created, id is assigned = 1 automatically. Then 2, 3, 4 and so on.

When data that has the id = 1 is generated, then it will never be generated again.

I want to store this dat ain Cassandra. I can set primary key as the id field, but i dont know how cassandra will create partitions for each record?

Will it create one partition for each record?

Or will it create range partition by primary key. For example; id from 1 to 100 is the first partition, 100-200 is the second partition etc.


Solution

  • In Cassandra, the partition key uniquely identifies a single partition (record) in the table. For clarification, the primary key:

    • must have 1 partition key
    • zero or more clustering columns

    So the primary key doesn't equate to a range of partitions.

    Compared to traditional RDBMS which have two-dimensional tables, Cassandra tables have the traditional 2D tables but can also be 3D or more. The power of Cassandra is that tables can be multi-dimensional meaning each partition can have one or more rows (it can have thousands).

    If you're interested, I've explained this in a bit more detail with examples in this post -- https://community.datastax.com/questions/6171/. Cheers!