Creating a keyspace

Add a keyspace and set the replication factor.

A keyspace is similar to a relational database schema. A keyspace is the top-level container for database objects.

In Cassandra, data is replicated across nodes in a cluster to ensure reliability and fault tolerance.

Each keyspace has a replication strategy and a replication factor:
  • Simple strategy replication (SimpleStrategy): Applies the same replication setting across the cluster. Only use in test environments.
  • Network topography replication (NetworkTopologyStrategy): Applies the replication setting for each datacenter. Use in production environments.
  • Replication factor: The number of nodes that contain copies of the data. In general, set to this to at least 3. Lower numbers are acceptable for simple test environments.
For details, see Data replication.

The examples in this document feature a keyspace that stores cycling race information. For simplicity, the example keyspace uses SimpleStrategy replication with a replication factor of 1. This means that the replicated data is identical across all datacenters in the cluster and there are no replica nodes.

  1. Create a keyspace to store the cycling information:
    WITH replication = {
      'class' : 'SimpleStrategy',
      'replication_factor' : 1
  2. Use the keyspace as the default in future CQL commands:
    USE cycling;