What is Cassandra Keyspace?

The Cassandra Keyspace is the outermost container of data. Cassandra Keyspace is similar to the Database in Relation Database management System(RDBMS) and is used to store the column families schema, and defines the data replication in Cassandra Architecture. In Cassandra Cluster, there could be one or more keyspace per node. The Cassandra Keyspace has many attributes which define the replication factor, Datacenter details, and replica. The Data stored in the keyspace are separate from one another.

Components of Cassandra Keyspace?

The following are some of the key components of Cassandra Keyspace that we can use during the creation of Keyspace.

Replication Strategy:

The Cassandra Replication Strategy is used to provide the high availability, fault tolerance, and reliability of data by replicating it on multiple nodes. Using Replication we can define the number of nodes where replica will be placed.

The could be two possible Cassandra Strategies that are mentioned below.

1. Simple Strategy

The Cassandra Simple Strategy Replication is used for testing and development work in case the cluster is deployed to use one data center. In this replication Strategy, the first replica will be decided by the partitioner and then clockwise the replication will be applied on the next node in the cluster.

2. Network Topology Strategy

The Cassandra Network Topology Strategy is used to deploy the cluster on multiple data centers. Network Topology can be used for the production as well as the Development system. In this Strategy, the data is put on the nodes of the different racks to avoid any loss in case of failure.

Replication Factor:

The Replication Factors determine the number of replicas of a row that will be stored on each node. The minimum replica is two which indicates that in case of node failure there won't be an operational impact because another replica is there on another node. So it is advisable to set the three replica copies of the row to achieve the high availability of data.

Cassandra Create Keyspace

We can use the Create Keyspace command to create the keyspace in Cassandra.

CREATE keyspace [ IF NOT EXISTS ] keyspacename
WITH options;

In the following section, we will create a Cassandra Keyspace named cloudduggu. We will use the below command to create it. We will use SimpleStrategy replication and replication_factor 1.

cqlsh> CREATE keyspace cloudduggu
   ... WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor' : 1};


The following output will come once the Keyspace is created.

cassandra create keyspace cloudduggu

Verify Cassandra Keyspace

There was no output text comes post-execution of Create Keyspace command hence let's verify the Keyspace using Describe command. The DESCRIBE KEYSPACES; will show all the keyspaces present in Cassandra. We will use the DESCRIBE cloudduggu; to check the detail of cloudduggu keyspace.

cqlsh> describe keyspaces;
cqlsh> describe cloudduggu;


We can see the definition of creating keyspace in the below output also we see the durable_writes is true which means Cassandra will use the commitlog to make changes in the cloudduggu keyspace.

cassandra describe keyspace cloudduggu

Use Cassandra Keyspace

To use the Cassandra Keyspace the command is USE.

cqlsh> USE cloudduggu;

cassandra use command cloudduggu