pranali.khanna101994_189965 avatar image
pranali.khanna101994_189965 asked Erick Ramirez edited

How does replication work?

As per Doc,

Each Node in cassandra is responsible for range of hash value of partition key (Consistent hashing).

By default casssandra uses MurMur3 partitioner.

So on each node in cassandra there will be multiple partition keys availaible. For same partition key there will be only one record on one node,other copies will be available on other nodes based on replication factor .

How replication works when we say data is retrieved and stored as per partition key and partition key hashes to a value which depicts the node on which it needs to store ?

Also , can we have same partition key available on 2 nodes ? how is replication taking place as every record before writing , the location where to write is based on partition key .

So when RF=3 let's sat this record gets replicated on other 2 nodes what if they do not have that same partition key available? I mean how replication takes place in lieu of partition key and when we query the data which node responds among the 3 nodes ?

10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

bettina.swynnerton avatar image
bettina.swynnerton answered bettina.swynnerton commented

Here is an old blog, but it is still a good source of information on this topic:

quoted from this blog:

When data is inserted into the cluster, the first step is to apply a hash function to the partition key. The output is used to determine what node (and replicas) will get the data. The algorithm used by Apache Cassandra utilizes Murmur3 which will take an arbitrary input and create a consistent token value. That token value will be inside the range of tokens owned by single node. In simpler terms, a partition key will always belong to one node and that partition’s data will always be found on that node.

So, the partition key belongs to only one node.

The replication (and which nodes will have a replica of the partition) is then defined by the replication strategy (see the doc linked below). For example, with SimpleStrategy, replicas are placed on the next nodes clockwise in the ring, so the partition key, the replication strategy and the ring structure identify which nodes have the replicas.

9 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

pranali.khanna101994_189965 avatar image pranali.khanna101994_189965 commented ·

Hi, Thanks for the answer . I have one doubt that if the same record is replicated on 2 or more replicas via replication factor that means partition key along with that record is also replicated there. so efficieny is ensured ? How cassandra ensured that partition key

belongs to one node when we have same data across different nodes ?

0 Likes 0 ·
bettina.swynnerton avatar image bettina.swynnerton ♦♦ pranali.khanna101994_189965 commented ·

Yes, you are of course right, the partition will be on several nodes if it is replicated to several nodes.

But the partition key resolves to a unique token value, and that token belongs to only one node. This is where we will definitely have one replica for the partition. The other replicas are then determined based on the replication strategy and the ring structure, and the unique token for that partition key.

What do you mean by "is efficiency ensured"?

0 Likes 0 ·
pranali.khanna101994_189965 avatar image pranali.khanna101994_189965 bettina.swynnerton ♦♦ commented ·

By efficiency I meant for example: there is a table called Monthly Weather Forecast and partition key is City. If we want to retrieve data for say 'Delhi' it must lie on one single node right ?

so when we say RF=3 we say this record with Partition key as Delhi is stored on other 2 nodes as well. So if a partition key and data exists on multiple nodes that is Partionkey 'Delhi' will reside on other node also. How we ensure efficency?

0 Likes 0 ·
Show more comments