This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In the previous day, I shared some of the essential key concepts of the Cassandra Architecture.
In this post, I am sharing the basic architecture of reading and writing operations of Cassandra.
Cassandra Ring:
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 assigns 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 for preparing the set of data for each node.
Cassandra has three different types of Partitioners, Murmur3Partitioner (default), RandomPartitioner and a ByteOrderedPartitioner.
Each node is performing replications of data basis 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 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 in 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, 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 whether it exists in SSTable or not.