top of page

Casandra

  • Writer: Anand Nerurkar
    Anand Nerurkar
  • Nov 3, 2023
  • 3 min read

CasandraN is NoSQL DB,key value,columnar DB with distributed computing,clustering,high availability, highly scalable,fault tolerance,query by design.

ree


ree

Apache Casandra Architecture

====

Casandra is masterless,peer to peer n/w ,distributed cluster in ring format. Horizontal scale by adding nodes to cluster, query by design, fast write aand read.


ree

How data is being distributed across different noce in a cluster

---

Partitioning palys bery important role , not only distributing data across different node in parttion, but also help in retrieving data faster by partition.


Casandra make use of Consistent hashing algorithm. This algorithm make use of token and ring.


Let us assume we have cluster of 5 nodes, each nide being assigned a token. Each node is connected in ring format.


Each data has key and value. Consitent hashing is done on key and being assigned a token. There will be token to node mapping as shown below and accordingly data is writtern to that node. Based on replication factor, casandra will wlak the ring in clokwise direction and write the replica to n2-t2,node3-t3 fpr repFactor=3.




ree

Or better efficency we can have token ranges assgiend to nodes.

ree

Token map- token to node mapping

Virtual node- is on one physical node only, but different toekn is being assigned, each token is being considred as parttion. these are called virtual node.


How data should be replicated

===

Casandra follows 2 strategy as below ,depending on the use case , we will make use of one.


  1. Network Topology Strategy---as part of replication, we make use of replication factor and accordingly create that many replica and maintain those replica across nodes in cluster. With this strategy, replica may be in rack1,rack 2 in data center 1 , rack 4 in data center 2. so even if one data center outage happend, we have other data center serving the request, thus provide HA and fault tolerance. This is being used in case we need to maintain data replica across multiple data center.

  2. Simple Strategy--data will be replcated in random fashion ,may be in rack1, rack2 or rack3 in a data center .

ree


Data Versioning

===

Every data which is being writtern to node, maintain timestamp. if there are concurrent requrst come for the same key id, each data will be written with timestamp. which data will be returned to client, data with higher timestamp will be returned to client, this is where it follows Last Write Wins principle. This is where Repairing happends as a part of casandra operation.


Repairing

1- Full repairing- all replica will be synched as per latest write win priciple

2. sub range repairing- only few parttion will be reapired

2.Incremental - will identify replica update, which token or parttion it belongs, only those partioned will be synched.


ree


ree

data consistency

===

we can configure consistency or write /read request. how cansandra make sure that write/read has been done successfully and responsd to the client and return response. This is where consistecny play role.


if consistecny=2, Replication Factor=3, that mean data will be writtern to 3 nodes in ring format and will expect minimum 2 node to respond with acknoledgement that data is being written.Once it receive 2 ack from 2 nodes, then it confirm that data is being written to nides and send respnse to client.


we can have consistecny as below

Consistency =1

Consistency =2

Consistency =3

Consistency =QUORAM --means majority of the nodes send the acknoledgement saying that data is being written. Majority = Replication factor/2


say RF=10. majority =10/2=5 , atelast 5 node sends acknowledgement thta data is being written


Consistency =ALL = all replica respnsd with ack that data is being written


Consistency =Local QUORAM-- majority of nodes from local data center respond with ack that data is being written


Consistency =Each QUORAM-- majority of nodes in each data center respond with ack that data is being written


Consistency =Local ONE-- one of nodes in local data center respond with ack that data is being written


Consistency =ANY-- any data center either local or remote respond with ack that data is being written


ree

Failover Detection

===

IT make use of heartbeats and get the response from the node. if node respond with heaetbeats, then it maintain the state for that node ,alogn with that it gets heartbeat of neigboring node and maintian the state. This state is then shared among the node so that node does not send the request to dead nodes. This is where it make use of gossiping protocol ro gossip about node state with others. fews nides are makntedas seed nodes which we configure it at bootstrap time.

ree


ree

follows simple query model, need to desgin data model , read should come from dingle partition only.

read from multiple partion, join operation is not supported. we make use of CQL to query casandra

ree

Storage option

==


ree
  1. commit log

  2. memtable

  3. sstable-physical storage-disk storage.


ree

ree

ree

ree

ree

ree

ree

ree

Data Modelling

===

important to think in terms which column will be having primary key, this column will be used to query, withing that partion we need to sort data based on column, that column should be clustered key


ree

ree

Casandra Operation

====

operational side of casandra


always prefer that route which offer low latency


ree

ree

ree

ree

ree

ree

ree

ree

 
 
 

Recent Posts

See All

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
  • Facebook
  • Twitter
  • LinkedIn

©2024 by AeeroTech. Proudly created with Wix.com

bottom of page