Friday, 10 January 2020

Cassandra: Keyspaces


Keyspaces are the top level building blocks to organize the data in Cassandra. Whereas Cluster is a container for keyspaces.

If you are from RDBMS (Relational Database Management Systems) background, you can map keyspace to a database in RDBMS world. Like a database in RDBMS, a keyspace has a name and attributes (replication_factor, class etc.,) associated with it.

In RDBMS, a. database is collection of tables, whereas in Cassandra,  keyspace is a collection of column families. You can map column families to tables in RDBMS.

A keyspace contain
A keyspace can contain
a.   Tables
b.   Views
c.    User-defined Types
d.   Functions
e.   Aggregates

Apart from acting as a container for data structures like tables, indexes, a keyspace can hold some extra important attributes.

For example, while creating a keyspace, you can specify the replication startegy, this attribute deals with 'how data replications are made in cassandra cluster'.

Example
CREATE keyspace cassandratutorial WITH REPLICATION =
{
         'class' : 'SimpleStrategy',
         'replication_factor' : 3
};

Above statement creates a keyspace 'cassandraTutorial' and set the 'replication_factor' to the value 3. That means, data is replicated in 3 different nodes.

Why do we maintain replications of data?
To achieve high availability, Cassandra maintain replications of the data. For example, if a node in the Cassandra cluster fails, then the data is given from other node.

Previous                                                    Next                                                    Home

No comments:

Post a Comment