Cassandra Data Model (Keyspace, Tables, Column Families, etc.)

Keyspace

In Cassandra, the key unit for organizing data is the Keyspace. Every application requires a keyspace to store its data.

Keyspace Options

  • CREATE KEYSPACE [keyspace_name] [options]
  • keyspace_name: Keyspace name
  • OPTION: Optional parameters used for customizing keyspace behavior
  • replication: How data is distributed (e.g. Standard, Simple, etc.)
  • durability: Data persistence settings (e.g. Normal, Low)
  • columnFamily: Specifies the name of the column family

Table

In Cassandra, each table is a set of related columns, which can be fixed or variable in number. Cassandra tables are referred to as Table

Create Table Options

  • CREATE TABLE [keyspace_name].[table_name] ( column1 data_type , column2 data_type , ...)

Column Family

In Cassandra, each column in a table is composed of one or more column families (ColumnFamily). Cassandra column families are time-series based.

Create ColumnFamily Options

  • CREATE COLUMNFAMILY [column_family_name] ( column1 data_type , column2 data_type , ...)

Examples and Notes

In practical use, Cassandra's data model needs to be adjusted according to specific requirements. For example:

  • KEYSPACE: When creating a new keyspace, consider how to distribute data to maintain high availability.
  • TABLE: The number of column families in each table may vary, and Cassandra needs to adjust partitioning strategies accordingly to ensure data consistency and scalability.
  • Column Family: Understanding the usage of different column families within each table helps optimize data storage when creating or updating tables.