question

nagasree963_193876 avatar image
nagasree963_193876 asked Erick Ramirez commented

What is the write replica and read replica?

I am using cassandra operator version:1.1.0 and application version 3.11.6. How to know what is the write replica and read replica . Can anyone please explain it.

replication
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

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez commented

Your question doesn't really have anything to do with the cass-operator. The read and write replicas are one and the same -- they are just "replicas".

In Cassandra, replicas are nodes which store copies of the data for reliability and fault tolerance. If you had a keyspace defined with 3 replicas in a DC like this example:

CREATE KEYSPACE community WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1': '3'}

It means that in DC1, the data in the tables for keyspace community has copies stored in 3 of N nodes in the data centre (N being the number of nodes in the ring).

Each partition in the table gets distributed around the ring (a Cassandra data centre) by the partitioner -- a hashing function that converts the partition key into a token value. Each node in the ring owns a token range (multiple ranges for clusters configured with virtual nodes) and it will store partitions whose tokens are within the range it owns.

Let me illustrate with this simplified diagram:

In this example diagram:

  • node 1 is the coordinator node which is blue green in the diagram
  • node A is purple in the diagram (token 63)
  • node B is red in the diagram (token 75)
  • node C is blue in the diagram (token 88)

The coordinator determines the primary owner of the partition through the partitioner's hashing function. In the example above, the partition key has a token value of 59. Since the purple node owns tokens in the range 51 to 63 (indicated by the purple "inner-ring"), the coordinator knows that it is the primary owner for token 59 (we'll call it "primary replica").

The replicas are the immediate neighbours of the "primary replica". A replication factor of 3 in the ring (data centre) means that Cassandra stores 3 copies of the partition so the primary owner (purple) plus its 2 neighbours (red and blue) hold the 3 copies.

I imagine you'll have lots of follow up questions but before you post them, I highly recommend you watch the video on Replication in the DS201 Cassandra Foundations course at DataStax Academy. That video will explain a lot to you. In fact, I recommend you do the course to save you a lot of time. Cheers!


replicas.png (447.1 KiB)
2 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.

nagasree963_193876 avatar image nagasree963_193876 commented ·

Thank you so much. I will do it

0 Likes 0 ·
Erick Ramirez avatar image Erick Ramirez ♦♦ nagasree963_193876 commented ·

Good to hear. Cheers!

0 Likes 0 ·