Read and Write path in Cassandra

Prerequisites –

Write Path Execution in Cassandra :

  • In Cassandra, while writing data, writes are written to any node in the cluster (coordinator).
  • when any user will insert data, it means they write the data first to commit log then to memtable.
  • When any user will write the data, every write will include a timestamp.
  • Once memtable starts getting full then it is flushed to disk periodically (SSTable).
  • After that a new memtable is created in memory.
  • In the case of write path execution, deletes are special write cases which are called a tombstone.

Inserting Data :
In case of inserting data in Cassandra, we will create a keyspace and then create a table and then insert data into the table.

Example –

// Creating a keyspace
create keyspace UniersityData
replication = {'class': 'SimpleStrategy', 'replication_factor' : '3' };

// Creating a table and declaring the columns
create table CSE_Student(
student_id int,
name text,
email text,
primary key(student_id)
);

// Using the newly created keyspace
use UniersityData;

// Inserting values in the table for all the columns
Insert into CSE_student(student_id, name, email) 
values(012345, 'Ashish', 'ashish@gmail.com');

Insert into CSE_student(student_id, name, email) 
values(012346, 'Abi', 'abi@gmail.com');

Insert into CSE_student(student_id, name, email) 
values(012347, 'Rana', 'rana@gmail.com');

Insert into CSE_student(student_id, name, email) 
values(012348, 'Aayush', 'aayush@gmail.com');

Insert into CSE_student(student_id, name, email) 
values(012349, 'harsh', 'haarsh@gmail.com'); 



Read Path Execution :



  • In Cassandra while reading data, any server may be queried which acts as the coordinator.
  • when we want to access read data then we contact nodes with requested key.
  • In a data center, on each node, data is pulled from SStable and is merged.
  • In Cassandra, while considering read consistency, we can check –
    Consistency < ALL performs read repair in the background (read_repair_chance).




Reading Data :
Write a cqlsh query to read data from CSE_student and give output for the same.

select * 
from CSE_student;

Output :

index student_id name email
0 12345 Ashish ashish@gmail.com
1 12346 Abi abi@gmail.com
2 12347 Rana rana@gmail.com
3 12348 Aayush aayush@gmail.com
4 12349 harsh haarsh@gmail.com

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.