On the previous day, I have shared some of the important key concepts of the Cassandra Architecture.
In this post, I am sharing the basic about read and write operations architecture of Cassandra.
Cassandra is using a consistent hashing algorithm to treat all nodes of the cluster equally.
A Cassandra cluster is visualised as a Ring in which different nodes are participating with the same name. It can exchange state information with a maximum of three other nodes.
A token range assigned to each node which determines its position in the cluster.
Cassandra is using Gossip Protocol so whenever any node starts, it obtains information about the other nodes by exchanging information with each other.
A Partitioner is responsible to prepare set of data for each node.
Cassandra has three different types of Partitioners, Murmur3Partitioner (default), RandomPartitioner and a ByteOrderedPartitioner.
Each node is performing replicates of data base on defined replication strategy. Basically there two types of replication strategy, one is Simple Strategy and second is Network Topology Strategy.
A Simple Strategy works in the clockwise and Network Topology basically works for multiple data centres.
How It executes Write Operations?
A Cassandra is Masterless distributed architecture and there is no any Master and Slave mechanism like any other distributed system.
At any given point of time, the client can connect to any node and that connected node called as a coordinator.
Based on the partition key and replication strategy, Coordinator forwards and replicates data to all applicable nodes.
Each node processes the request individually.
Every node first writes data into the commit log and then writes into the memtable.
The commit log ensures the durability because memtable is dealing with memory so whenever data is lost then we can use commit log to restore the data.
Whenever memtable is flushed or full, it is written to the SSTable (Sorted String Table) of the disk.
Every SSTable creates three files on the disk which include a bloom filter, a key index and a data file. Over a period of time a number of SSTables are created.
How It executes Read Operations?
As Cassandra is Masterless architecture so clients can connect to any node of the cluster ring.
Like write operation, chosen node is called as coordinator and is responsible for returning the requested data.
A row key must be supplied for every read operation. The coordinator uses the row key to determine the first replica.
If replica has a different version of the data, coordinator returns the latest version to the client by issuing read repair command with the older version of the data.
Each read request fetches the data from memtable and SSTables after that it merged this data and returned to the coordinator.
Internally SSTables are using a Bloom Filter to check requested row key weather it is exists in SSTable or not.
Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.
If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.
I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.