Search code examples
cassandrareplication

Cassandra different replication factor across cluster


Is is possible to have different replication settings on different nodes of the same cluster? (All DCs have same keyspace/tables, but different replication settings)

We would like to have DC1 and DC2 collecting sensor data on different geographical locations, and sending these to a DC3. So DC3 contains all data from DC1 + DC2.

However, DC1 and DC2 should not contain each other's data (only data which was written by local clients).

Can this be achieved in Cassandra by having different keyspace replication settings on the DCs?

  • On DC1: 'DC1':1, 'DC3':1
  • On DC2: 'DC2':1, 'DC3':1
  • On DC3: 'DC3':1

Solution

  • You can't really do this with NetworkTopologyStrategy. Depending on how much effort you want to put into this you could implement your own replication strategy. I don't think this is very common, but Cassandra does allow it and it likely wouldn't be too difficult to implement what you want (take a look at NTS's implementation as an example).

    If you don't want to implement your own strategy I would recommend creating 2 keyspaces with the following configuration:

    CREATE KEYSPACE keyspace1
    WITH replication = {
        'class' : 'NetworkTopologyStrategy',
        'DC1' : 1,
        'DC3' : 1
    };
    
    CREATE KEYSPACE keyspace2
    WITH replication = {
        'class' : 'NetworkTopologyStrategy',
        'DC2' : 1,
        'DC3' : 1
    };
    

    and then depending on the location of your client you would use either keyspace.