Since its inception at Facebook, Cassandra has become one of the most popular Apache projects. It is a widely-used open-source, high performance and distributed database and makes the lives of software engineers, data scientists, and web developers easier.
The users of this robust database solution include the likes of IBM, Facebook, Reddit, eBay, and Twitter.
However, to get familiar with Cassandra, you must know about its architecture and Apache Cassandra architecture can be a little tricky to understand.
That’s why we have created the following introductory guide on Cassandra architecture. It will make you familiar with all the necessary concepts of Cassandra architecture:
Basics of Cassandra Architecture
The Apache Cassandra architecture has no master or slave nodes. Instead, it has a ring-like architecture where the nodes are logically distributed in a ring. The architecture allows data to be distributed automatically across all nodes. Like HDFS, data in Cassandra gets replicated across the nodes for redundancy and is stored in memory. It uses the hash values of the keys to distribute data among the nodes in the cluster.
The Cassandra architecture allows the system to function irrespective of a single point of failure. This means if a cluster has a hundred nodes and one of them fails, the cluster would still be running. On the other hand, with Hadoop, the failure of a namenode would fail the entire system.
Cassandra architecture offers high scalability so a cluster can even have thousands of nodes. Moreover, you can add a new node to a cluster without interrupting its operations.
Apart from the features, we discussed above, Apache Cassandra architecture also supports multiple data centres and enables data replication across data centres.
Topology and Design
Cassandra architecture is based on a distributed system architecture. The simplest version of Cassandra can run on one machine and work well with basic testing. One Cassandra instance is called a node.
Cassandra offers horizontal scalability where you can add more than one node as a component of a cluster. It works with peer to peer architecture where each node is connected to every other node. Every Cassandra node performs all database operations and servers client requests without a master node.
Explore our Popular Software Engineering Courses
This peer-to-peer distributed architecture ensures that a single point of failure doesn’t cause the entire system to fail. Clusters in Cassandra can communicate with each other for numerous functions. The following concepts are vital for such communication:
Gossip is a Cassandra protocol its nodes use for peer-to-peer communication. It informs a node about the other nodes’ states. Every second, one node performs gossip with up to three other nodes and every gossip message follows specific formats and version numbers to keep the communication efficient.
Explore Our Software Development Free Courses
|Blockchain Technology||React for Beginners||Core Java Basics|
Every node in Cassandra configures a list of seeds which is a list of other nodes. A seed node doesn’t have any purpose other than bootstrapping a node when it first joins a cluster. After bootstrap, a node doesn’t require a seed on restarting. It’s best to use two or three seed nodes per Cassandra data centre and keep the seeds list uniform.
In Cassandra, data is stored in tables where every table is organized into rows and columns. Moreover, tables in Cassandra are grouped in keyspaces such as tables on customer data can all be grouped in one keyspace while tables on business transactions can be stored in another.
Every table has a primary key which is divided into clustering columns and partition key. Note that the clustering columns are optional. Cassandra uses the partition key to index the data. All the rows with a common partition key constitute one data partition, the basic unit for data partitioning.
In-Demand Software Development Skills
Partitioning in Cassandra
In Cassandra, a partitioner converts partition keys into tokens. There are multiple partitioner options present in Cassandra where the Murmur3Partitioner is the default. Every token is assigned an integer value between -2^63 to +2^63-1, and the name of this range is the token range.
Every Cassandra owns a part of this range and it mainly possesses data related to the range. We use a token to locate the data precisely among the nodes.
You can understand the ownership system with this concept: If a cluster has only one node then that node would own the complete token range. With the addition of more nodes, the token range ownership would get split accordingly.
Read our Popular Articles related to Software Development
Cassandra simplifies the token calculation and assignment challenges by using virtual nodes, also known as Vnodes.
It divides a cluster into numerous virtual nodes to assign tokens and every physical node gets an equal quantity of Vnodes. The default number of Vnodes owned by a node is 256. You can set the same by using the num_tokens property. When you add a new node to a cluster, the token allocation algorithm would allocate the required tokens by using the Vnodes.
Cassandra replicates the data present in every keyspace with a replication factor. One primary replica of the data remains with the token owner node while the rest are placed by Cassandra on particular nodes through its replica placement strategy. Note that all replicas have equal importance for most database operations.
Two settings affect replica placement in Cassandra, which are snitch and the replication strategy. Snitch determines the data centre and the rack a node belongs to. They are responsible for informing Cassandra about the topology for keeping things efficient.
The replication strategy is set at the keyspace level and there are two of them: NetworkTopologyStrategy and simple strategy. The former is a rack and data centre aware while the latter is not.
Every distributed system works based on the CAP theorem. According to this theorem, any distributed system can properly deliver any two out of the three properties, Consistency, Availability, and Partition-tolerance.
In Cassandra, you can choose between availability and consistency. This means the data can either be highly consistent with lower availability or highly available with low consistency.
The concept of requesting a specific number of acknowledgements is called tunable consistency and you can apply it at the individual query level.
In this process, the data is written to a comment log on a disk and then sent to a responsible node according to the hash value.
After that, nodes write data to an in-memory table called memtable from where the data is written to a “sstable” in memory. Next, it gets updated to the actual table.
If the responsible node is down for some reason, the data gets written to another node.
Learn More About the Cassandra Architecture
Understanding Apache Cassandra architecture would help you understand how this solution works. By now, you also know why Cassandra stands out in the competition and why it’s so popular.
If you’re interested in learning more about databases, you can check out the following resources:
On the other hand, if you’re looking for a personalized learning experience, we recommend taking a data science course. At upGrad, we offer a PG Diploma in Data Science and a Master of Science in Data Science. These courses will teach you all the necessary skills to become a data science professional.
If you are interested to know more about Big Data, check out our Advanced Certificate Programme in Big Data from IIIT Bangalore.
Check our other Software Engineering Courses at upGrad.
What are clusters in Cassandra?
A cluster is a group of nodes that together form a single system. Cassandra clusters are one of the shells that make up the Cassandra database as a whole. A cluster is essentially a database's exterior shell or storage unit. Cassandra clusters are made up of many storage levels. Each layer is made up of layers that are themselves made up of layers. The database's primary data source is always a cluster. Users can start the Cluster Builder by issuing a series of instructions. It enables users to do a variety of detailed actions on a cluster as it is being created.
What makes the Gossip protocol important in Cassandra?
In Cassandra, the Gossip Protocol is a peer-to-peer communication protocol that allows nodes to select whom they wish to share their state information with. The nodes share information regarding themselves and the other nodes about whom they have gossiped or communicated, allowing all nodes in the cluster to learn very quickly about each other. In the Gossip protocol, the technique of acknowledging messages aids in failure detection. Because a node can't transmit or receive information when it is down or failing, acknowledgements are not accepted.
What are the benefits of Cassandra?
Cassandra has several advantages. To begin with, the most significant benefit of using Apache Cassandra is its elastic scalability, which allows a large number of servers to be added and the cluster to be scaled up and down as needed. Second, because Cassandra is an Apache software, it is open source, which means it is absolutely free to use. For execution, Cassandra uses a peer-to-peer architecture, which implies that all servers are on the same level, and any computer may respond to a client request. As a result, there are only a few opportunities for failure. It encrypts the data and distributes it across different servers. If one server goes down or is hacked, the user may easily get the data from another location.