The Wayback Machine - https://web.archive.org/web/20240922204317/https://www.geeksforgeeks.org/apache-cassandra-nosql-database/
Open In App

Apache Cassandra (NOSQL database)

Last Updated : 25 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this article, we will learn the basics of Apache Cassandra and the basics of CQL (Cassandra Query Language) operations like Create, insert, delete, select, etc. 

Apache Cassandra

Apache Cassandra is an open-source NoSQL database that is used for handling big data. Apache Cassandra has the capability to handle structured, semi-structured, and unstructured data. Apache Cassandra was originally developed at Facebook after that it was open-sourced in 2008 and after that, it became one of the top-level Apache projects in 2010.

Features of Cassandra:

1. it is scalable.

2. it is flexible (can accept structured, semi-structured, and unstructured data).

3. it doesn’t support ACID Transactions

4. it is highly available and fault-tolerant.

5. it is open source.

 Figure-1: Masterless ring architecture of Cassandra 

Apache Cassandra is a highly scalable, distributed database that strictly follows the principle of the CAP (Consistency Availability and Partition tolerance) theorem. 

Figure-2: CAP Theorem

In Apache Cassandra, there is no master-client architecture. It has a peer-to-peer architecture. In Apache Cassandra, we can create multiple copies of data at the time of keyspace creation. We can simply define replication strategy and RF (Replication Factor) to create multiple copies of data. Example:

CREATE KEYSPACE Example
WITH replication = {'class': 'NetworkTopologyStrategy',
'replication_factor': '3'};

In this example, we define RF (Replication Factor) as 3 which simply means that we are creating here 3 copies of data across multiple nodes in a clockwise direction.

 Figure-3: RF = 3 

cqlsh: CQL shell cqlsh is a command-line shell for interacting with Cassandra through CQL (Cassandra Query Language). CQL query for Basic Operation: 

Step1: To create keyspace use the following CQL query.

CREATE KEYSPACE Emp
WITH replication = {'class': 'SimpleStrategy',
'replication_factor': '1'};

Step2: CQL query for using keyspace

Syntax: 
USE keyspace-name
USE Emp;

Step-3: To create a table use the following CQL query.

Example:
CREATE TABLE Emp_table (
name text PRIMARY KEY,
Emp_id int,
Emp_city text,
Emp_email text,
);

Step-4: To insert into Emp_table use the following CQL query.

Insert into Emp_table(name, Emp_id, Emp_city, Emp_email) 
VALUES ('ashish', 1001, 'Delhi', 'ashish05.rana05@gmail.com');
Insert into Emp_table(name, Emp_id, Emp_city, Emp_email)
VALUES ('Ashish Gupta', 1001, 'Bangalore', 'ashish@gmail.com');
Insert into Emp_table(name, Emp_id, Emp_city, Emp_email)
VALUES ('amit ', 1002, 'noida', 'abc@gmail.com');
Insert into Emp_table(name, Emp_id, Emp_city, Emp_email)
VALUES ('dhruv', 1003, 'pune', 'xyz@gmail.com');
Insert into Emp_table(name, Emp_id, Emp_city, Emp_email)
VALUES ('shivang', 1004, 'mumbai', 'test@gmail.com');
Insert into Emp_table(name, Emp_id, Emp_city, Emp_email)
VALUES ('aayush', 1005, 'gurugram', 'cass_write@gmail.com');
Insert into Emp_table(name, Emp_id, Emp_city, Emp_email)
VALUES ('bhagyesh', 1006, 'chandigar', 'welcome@gmail.com');

Step-5: To read data use the following CQl query.

SELECT * FROM Emp_table;


Similar Reads

Cassandra (NoSQL) Database
Recent Topics on Cassandra: Introduction Cassandra Architecture Cassandra Query Language Data Types Collection Data Types Functions in Cassandra Data Modelling and Designing Security Performance Monitoring Backup and Restore Data Misc Introduction Apache Cassandra (NoSQL) database Introduction to Apache Cassandra Role of keys in Cassandra schema de
2 min read
Cassandra vs DynamoDB: Best NoSQL Database for 2024
Selecting the correct database solution counts much in developing an app with high scalability and performance. Most commonly, traditional relational databases are not well-suited to manage huge volumes of data and its diversity which is an attribute of modern applications. NoSQL databases come in place here by providing dynamic schemas and horizon
10 min read
What Distinguishes Column-Oriented NoSQL From Document-Oriented NoSQL
NoSQL databases have gained significant popularity for their flexibility and scalability in managing large volumes of diverse data. Two common types of NoSQL databases are column-oriented and document-oriented databases. In this article, we will learn about Document-Oriented NoSQL Databases and Column-Oriented NoSQL Databases along with their Chara
5 min read
Apache Cassandra tools
Prerequisites - Introduction to Apache Cassandra Apache Cassandra (NOSQL database) Architecture of Apache Cassandra In this article, we are going to discuss the tools of Apache Cassandra which help to perform in various aspects of tasks such that the status of the node, the status of the ring, back up and restore data, etc. The CQL shell (cqlsh) -
3 min read
Architecture of Apache Cassandra
Avinash Lakshman and Prashant Malik initially developed Cassandra at Facebook to power the Facebook inbox search feature. Facebook released Cassandra as an open source project on google code in July 2008. It became an Apache incubator project in March 2009. It became one of the top level project in 17 Feb 2010. Fueled by the internet revolution, mo
5 min read
Overview of Data modeling in Apache Cassandra
In this article we will learn about these three data model in Cassandra: Conceptual, Logical, and Physical. Learning Objective: To Build database using quick design techniques in Cassandra. To Improve existing model using a query driven methodology in Cassandra. To Optimize Existing model via analysis and validation techniques in Cassandra. Data mo
3 min read
Collection Data Type in Apache Cassandra
Collection Data Type in Cassandra In this article, we will describe the collection data type overview and Cassandra Query Language (CQL) query of each collection data type with an explanation. There are 3 types of collection data type in Cassandra. 1. SET 2. LIST 3. MAP Let discuss one by one. 1. SET: A Set is a collection data where we can store a
3 min read
Pre-defined data type in Apache Cassandra
Prerequisite - User Defined Type (UDT) in Cassandra In this article, we will discuss different types of data types in Cassandra which is used for various purpose in Cassandra such that in data modeling, to create a table, etc. Basically, there are 3 types of data type in Cassandra. Lets have a look. Figure - Data Types in Cassandra Now, here we are
4 min read
Five main benefits of Apache Cassandra
In this article, we will discuss the 5 main benefits of Apache Cassandra in which scalability, High Availability, High Fault Tolerance, High Performance, Multi-Data Center, and Hybrid Cloud Support are the main factors. Prerequisite - Introduction to Apache Cassandra Scalability : In Cassandra, If a system will be scalable then your business would
3 min read
SSTable in Apache Cassandra
In this article, we are going to discuss SSTable which is one of the storage engines in Cassandra and SSTable components and also, we will cover what type of information kept in different database file in SSTable. Let’s discuss one by one. SSTable : It is one of the storage engines in Apache Cassandra i.e storage for Immutable data file for row sto
3 min read
Node in Apache Cassandra
In this article, we are going to discuss what is a node in Cassandra, information of node, how we can access the information about the node, and by using Nodetool utility we will also discuss some nodetool commands. let's discuss one by one. Node : A node in Cassandra contains the actual data and it's information such that location, data center inf
2 min read
Concept of indexing in Apache Cassandra
Indexing in Apache CassandraIn Apache Cassandra, data can be accessed using attributes that are part of the partition key. For example, if Emp_id is a column in an Employee table and it serves as the partition key, you can filter or search data using this key. In this case, the WHERE clause can be used to define conditions over the attribute to ret
4 min read
Strategies For Migrating From SQL to NoSQL Database
Migrating from a SQL database to a NoSQL database can be a complex process, but there are several strategies that can be used to make the transition smoother. Here are some common strategies for migrating from SQL to NoSQL: Analyze the current SQL schema and data model: Before starting the migration, it's important to analyze the current SQL schema
7 min read
Difference between Relational database and NoSQL
1. Relational Database : RDBMS stands for Relational Database Management Systems. It is most popular database. In it, data is store in the form of row that is in the form of tuple. It contain numbers of table and data can be easily accessed because data is store in the table. This Model was proposed by E.F. Codd. 2. NoSQL : NoSQL Database stands fo
2 min read
Introduction to Graph Database on NoSQL
A graph database is a type of NoSQL database that is designed to handle data with complex relationships and interconnections. In a graph database, data is stored as nodes and edges, where nodes represent entities and edges represent the relationships between those entities. Graph databases are particularly well-suited for applications that require
8 min read
Introduction to NoSQL Cloud Database Services
NoSQL Cloud Database Services are cloud-based database services that provide scalable, high-performance, and cost-effective solutions for storing and retrieving data. NoSQL (Not Only SQL) databases are designed to handle large volumes of unstructured, semi-structured, and structured data, and can easily scale horizontally to accommodate increased d
6 min read
Generation of Database Revolutions in NoSQL
The first generation of database revolutions occurred in the late 1960s and early 1970s when the relational model was first introduced. This was followed by the second generation of database revolutions in the late 1990s and early 2000s when NoSQL databases began to gain popularity. There have been a lot of talks lately about the "NoSQL" database r
6 min read
NoSQL Database Design
In the world of modern data management, NoSQL databases have emerged as powerful alternatives to traditional relational databases. NoSQL, which stands for "Not Only SQL" have a diverse set of database technologies designed to handle large volumes of unstructured, semi-structured, and structured data. In this article, we'll explore the fundamentals
4 min read
Mastering Database Integration in NestJS: Combining SQL and NoSQL
Choosing the right database is vital for your application's performance and scalability. SQL databases offer structured, reliable transactions, while NoSQL databases provide flexibility and easy scalability. This article explains how to integrate both types using NestJS, a modern Node.js framework. We'll guide you through setting up a NestJS applic
6 min read
Difference Between Apache Kafka and Apache Flume
Apache Kafka: It is an open-source stream-processing software platform written in Java and Scala. It is made by LinkedIn which is given to the Apache Software Foundation. Apache Kafka aims to provide a high throughput, unified, low-latency platform for handling the real-time data feeds. Kafka generally used TCP based protocol which optimized for ef
2 min read
Difference between Apache Hive and Apache Spark SQL
1. Apache Hive : Apache Hive is a data warehouse device constructed on the pinnacle of Apache Hadoop that enables convenient records summarization, ad-hoc queries, and the evaluation of massive datasets saved in a number of databases and file structures that combine with Hadoop, together with the MapR Data Platform with MapR XD and MapR Database. H
2 min read
Database Roles in CQL (Cassandra Query Language)
Cassandra Query Language (CQL) is the query language used to interact with Cassandra databases. Unlike traditional relational databases, Cassandra does not have a built-in concept of database roles. Instead, access control is managed at the object level, such as the keyspace, table, or column level. Cassandra provides a set of permissions that can
5 min read
Create database in Cassandra
In this article, we are going to discuss how to create the database in Cassandra. so, for better understanding you can read "Introduction to Cassandra" article before creating a database in Cassandra. Step-1: login into cqlsh you can log in into the cqlsh using Cassandra default credential. Now, here before creating a database you first need login
2 min read
What is Integration Databases in NoSQL?
In NoSQL databases, integration databases refer to databases that combine different types of NoSQL databases and/or traditional relational databases to provide a comprehensive and flexible data storage solution. This can help organizations to overcome some of the limitations of using a single type of database and to take advantage of the strengths
5 min read
NoSQL Data Architecture Patterns
Architecture Pattern is a logical way of categorizing data that will be stored on the Database. NoSQL is a type of database which helps to perform operations on big data and store it in a valid format. It is widely used because of its flexibility and a wide variety of services. Architecture Patterns of NoSQL: The data is stored in NoSQL in any of t
4 min read
Difference between Oracle NoSQL and Oracle
1. Oracle : Oracle is a relational database management system (RDBMS). It was developed by Oracle Corporation in 1980. It is the first database designed for grid computing that provides the most flexible and cost-effective way to manage information and application. It runs on major platforms like Windows, Unix, Linux, and macOS. It is a relational
2 min read
Key-Value Data Model in NoSQL
A key-value data model or database is also referred to as a key-value store. It is a non-relational type of database. In this, an associative array is used as a basic database in which an individual key is linked with just one value in a collection. For the values, keys are special identifiers. Any kind of entity can be valued. The collection of ke
3 min read
Difference between NoSQL and NewSQL
1. NoSQL : The term NoSQL is categorizing databases as descriptive as " No-SQL ". NoSQL is a comprehensive category of databases that are developed to overcome the problems generated by SQL databases. They are referred to as schema less documents which store the data in documents, graph, key-value, and non-ordered fashion.Advantages of NoSQL : They
2 min read
Challenges of NoSQL
A NoSQL originally referring to non SQL or non relational is a database that provides a mechanism for storage and retrieval of data. This data is modeled in means other than the tabular relations used in relational databases. For a variety of reasons, businesses rely on relational database technology that has been around for decades. Long-running,
4 min read
How NoSQL System Handle Big Data Problem?
Datasets that are difficult to store and analyze by any software database tool are referred to as big data. Due to the growth of data, an issue arises that based on recent fads in the IT region, how the data will be effectively processed. A requirement for ideas, techniques, tools, and technologies is been set for handling and transforming a lot of
2 min read
Article Tags :