Keyspace in Apache Cassandra

Connect with

Apache Cassandra
Well, in Cassandra Keyspace is similar to schema in RDBMS and Coulum-family is table in Apache Cassandra. This post is referring to Apache Cassandra 3.0.

Kayspace in Apache Cassandra

Creating a keyspace is the CQL counterpart to creating an SQL database. In Cassandra there are different options are available like replication factor, data center, replication strategy etc. Typically, a cluster has one keyspace per application. Replication is controlled on a per-keyspace basis, so data that has different replication requirements typically resides in different keyspaces.

When you create a keyspace, specify a strategy class for replicating keyspaces. Using the SimpleStrategy class is fine for evaluating Cassandra or with one data center with multiple nodes. For production use or for use with mixed workloads, use with appropriate available options.

Create a keyspace in Apache Cassandra

CREATE KEYSPACE user_keyspace
  WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };

Here , keyspace can be created with different available options in Cassandra, but I have opted to provide minimal optional with replication_factor=1, as this is test environment.

Create Keyspace with Different DataCenter

  WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 2};

here, dc1 is one data center with replication factor 3 and dc2 is another data center with replication factor 2. And NetworkTopologyStrategy is used in case of multi data center only.

Check created keyspaces

Check the keyspaces which were created earlier.

SELECT * FROM system.schema_keyspaces;


cqlsh:user_keyspace> SELECT * from system.schema_keyspaces;

 keyspace_name | durable_writes | strategy_class                                       | strategy_options
      userdemo |           True | org.apache.cassandra.locator.NetworkTopologyStrategy |      {"dc2":"2","dc1":"3"}
 user_keyspace |           True |          org.apache.cassandra.locator.SimpleStrategy | {"replication_factor":"1"}
        system |           True |           org.apache.cassandra.locator.LocalStrategy |                         {}
 system_traces |           True |          org.apache.cassandra.locator.SimpleStrategy | {"replication_factor":"2"}

(4 rows)


Datastax’s cqlsh

Your suggestions or comments are welcome to improve this post.

Connect with

3 thoughts on “Keyspace in Apache Cassandra

  1. Pingback: Rock
  2. Pingback: Simmi Arora
  3. Pingback: Urmila

Leave a Reply

Your email address will not be published. Required fields are marked *