blog/ribw/cassandra-an-introduction/index.html (view raw)
1<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta name=description content="Official Lonami's website"><meta name=viewport content="width=device-width, initial-scale=1.0, user-scalable=yes"><title> Cassandra: an Introduction | Lonami's Blog </title><link rel=stylesheet href=/style.css><body><article><nav class=sections><ul class=left><li><a href=/>lonami's site</a><li><a href=/blog class=selected>blog</a><li><a href=/golb>golb</a></ul><div class=right><a href=https://github.com/LonamiWebs><img src=img/github.svg alt=github></a><a href=/blog/atom.xml><img src=/img/rss.svg alt=rss></a></div></nav><main><h1 class=title>Cassandra: an Introduction</h1><div class=time><p>2020-03-05T00:00:45+00:00<p>last updated 2020-03-18T09:47:05+00:00</div><p>This is the first post in the Cassandra series, where we will introduce the Cassandra database system and take a look at its features and installation methods.<p>Other posts in this series:<ul><li><a href=/blog/ribw/cassandra-an-introduction/>Cassandra: an Introduction</a> (this post)</ul><p>This post is co-authored wih Classmate.<hr><p><img src=https://lonami.dev/blog/ribw/cassandra-an-introduction/cassandra-database-e1584191543401.jpg alt="NoSQL database – Apache Cassandra – First delivery"><h2 id=purpose-of-technology>Purpose of technology</h2><p>Apache Cassandra is a <strong>NoSQL</strong>, <strong>open-source</strong>, <strong>distributed “key-value” database</strong>. It allows <strong>large volumes of distributed data</strong>. The main **goal **is provide <strong>linear scalability and availabilitywithout compromising performance</strong>. Besides, Cassandra <strong>supports replication</strong> across multiple datacenters, providing low latency.<h2 id=how-it-works>How it works</h2><p>Cassandra’s distributed **architecture **is based on a series of <strong>equal nodes</strong> that communicate with a <strong>P2P protocol</strong> so that <strong>redundancy is maximum</strong>. It offers robust support for multiple datacenters, with <strong>asynchronous replication</strong> without the need for a master server.<p>Besides, Cassandra’s <strong>data model consists of partitioning the rows</strong>, which are rearranged into <strong>different tables</strong>. The primary keys of each table have a first component that is the <strong>partition key</strong>. Within a partition, the rows are grouped by the remaining columns of the key. The other columns can be indexed separately from the primary key.<p>These tables can be <strong>created, deleted, updated and queried****at runtime without blocking</strong> each other. However it does <strong>not support joins or subqueries</strong>, but instead <strong>emphasizes denormalization</strong> through features like collections.<p>Nowadays, Cassandra uses its own query language called <strong>CQL</strong> (<strong>Cassandra Query Language</strong>), with a <strong>similar syntax to SQL</strong>. It also allows access from <strong>JDBC</strong>.<p><img src=https://lonami.dev/blog/ribw/cassandra-an-introduction/s0GHpggGZXOFcdhypRWV4trU-PkSI6lukEv54pLZnoirh0GlDVAc4LamB1Dy.png> _ Cassandra architecture _<h2 id=features>Features</h2><ul><li><strong>Decentralized</strong>: there are <strong>no single points of failure</strong>, every **node **in the cluster has the <strong>same role</strong> and there is <strong>no master node</strong>, so each node <strong>can service any request</strong>, besides the data is distributed across the cluster.<li>Supports **replication **and multiple replication of <strong>data center</strong>: the replication strategies are <strong>configurable</strong>.<li>**Scalability: **reading and writing performance increases linearly as new nodes are added, also <strong>new nodes</strong> can be <strong>added without interrupting</strong> application <strong>execution</strong>.<li><strong>Fault tolerance: data replication</strong> is done **automatically **in several nodes in order to recover from failures. It is possible to <strong>replace failure nodes****without <strong>making</strong> inactivity time or interruptions</strong> to the application.<li>**Consistency: **a choice of consistency level is provided for <strong>reading and writing</strong>.<li><strong>MapReduce support</strong>: it is **integrated **with <strong>Apache Hadoop</strong> to support MapReduce.<li><strong>Query language</strong>: it has its own query language called **CQL (Cassandra Query Language) **</ul><h2 id=corner-in-cap-theorem>Corner in CAP theorem</h2><p><strong>Apache Cassandra</strong> is usually described as an “<strong>AP</strong>” system because it guarantees <strong>availability</strong> and <strong>partition/fault tolerance</strong>. So it errs on the side of ensuring data availability even if this means <strong>sacrificing consistency</strong>. But, despite this fact, Apache Cassandra <strong>seeks to satisfy all three requirements</strong> (Consistency, Availability and Fault tolerance) simultaneously and can be <strong>configured to behave</strong> like a “<strong>CP</strong>” database, guaranteeing <strong>consistency and partition/fault tolerance</strong>.<p><img src=https://lonami.dev/blog/ribw/cassandra-an-introduction/rf3n9LTOKCQVbx4qrn7NPSVcRcwE1LxR_khi-9Qc51Hcbg6BHHPu-0GZjUwD.png> <em>Cassandra in CAP Theorem</em><h2 id=download>Download</h2><p>In order to download the file, with extension .tar.gz. you must visit the <a href=https://cassandra.apache.org/download/>download site</a> and click on the file “<a href=https://ftp.cixug.es/apache/cassandra/3.11.6/apache-cassandra-3.11.6-bin.tar.gz>https://ftp.cixug.es/apache/cassandra/3.11.6/apache-cassandra-3.11.6-bin.tar.gz</a>”. It is important to mention that the previous link is related to the 3.11.6 version.<h2 id=installation>Installation</h2><p>This database can only be installed on Linux distributions and Mac OS X systems, so, it is not possible to install it on Microsoft Windows.<p>The first main requirement is having installed Java 8 in <strong>Ubuntu</strong>, the OS that we will use. Therefore, the Java 8 installation is explained below. First open a terminal and execute the next command:<pre><code>sudo apt update
2sudo apt install openjdk-8-jdk openjdk-8-jre
3</code></pre><p>In order to establish Java as a environment variable it is needed to open the file “/.bashrc”:<pre><code>nano ~/.bashrc
4</code></pre><p>And add at the end of it the path where Java is installed, as follows:<pre><code>export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/
5export PATH=$PATH:$JAVA_HOME/bin
6</code></pre><p>At this point, save the file and execute the next command, note that it does the same effect re-opening the terminal:<pre><code>source ~/.bashrc
7</code></pre><p>In order to check if the Java environment variable is set correctly, run the next command:<pre><code>echo $JAVA_HOME
8</code></pre><p><img src=https://lonami.dev/blog/ribw/cassandra-an-introduction/JUUmX5MIHynJR_K9EdCgKeJcpINeCGRRt2QRu4JLPtRhCVidOhcbWwVTQjyu.png> <em>$JAVAHOME variable</em><p>Afterwards, it is possible to check the installed Java version with the command:<pre><code>java -version
9</code></pre><p><img src=https://lonami.dev/blog/ribw/cassandra-an-introduction/z9v1-0hpZwjI4U5UZej9cRGN5-Y4AZl0WUPWyQ_-JlzTAIvZtTFPnKY2xMQ_.png> <em>Java version</em><p>The next requirement is having installed the latest version of Python 2.7. This can be checked with the command:<pre><code>python --version
10</code></pre><p>If it is not installed, to install it, it is as simple as run the next command in the terminal:<pre><code>sudo apt install python
11</code></pre><p>Note: it is better to use “python2” instead of “python” because in that way, you force to user Python 2.7. Modern distributions will use Python 3 for the «python» command.<p>Therefore, it is possible to check the installed Python version with the command:<pre><code>python --version
12</code></pre><p><img src=https://lonami.dev/blog/ribw/cassandra-an-introduction/Ger5Vw_e1HIK84QgRub-BwGmzIGKasgiYb4jHdfRNRrvG4d6Msp_3Vk62-9i.png> <em>Python version</em><p>Once both requirements are ready, next step is to unzip the file previously downloaded, right click on the file and select “Extract here” or with the next command, on the directory where is the downloaded file.<pre><code>tar -zxvf apache-cassandra-x.x.x-bin.tar.gz
13</code></pre><p>In order to check if the installation is completed, you can execute the next command, in the root folder of the project. This will start Cassandra in a single node.<pre><code>/bin/cassandra
14</code></pre><p>It is possible to make a get some data from Cassandra with CQL (Cassandra Query Language). To check this execute the next command in another terminal.<pre><code>/bin/cqlsh localhost
15</code></pre><p>Once CQL is open, type the next sentence and check the result:<pre><code>SELECT cluster_name, listen_address from system.local;
16</code></pre><p>The output should be:<p><img src=https://lonami.dev/blog/ribw/cassandra-an-introduction/miUO60A-RtyEAOOVFJqlkPRC18H4RKUhot6RWzhO9FmtzgTPOYHFtwxqgZEf.png> <em>Sentence output</em><p>Finally, the installation guide provided by the website of the database is attached in this <a href=https://cassandra.apache.org/doc/latest/getting_started/installing.html>installation guide</a>.<h2 id=references>References</h2><ul><li><a href=https://es.wikipedia.org/wiki/Apache_Cassandra>Wikipedia</a><li><a href=https://cassandra.apache.org/>Apache Cassandra</a><li><a href=https://www.datastax.com/blog/2019/05/how-apache-cassandratm-balances-consistency-availability-and-performance>Datastax</a><li><a href=https://blog.yugabyte.com/apache-cassandra-architecture-how-it-works-lightweight-transactions/>yugabyte</a></ul></main><footer><div><p>Share your thoughts, or simply come hang with me <a href=https://t.me/LonamiWebs><img src=/img/telegram.svg alt=Telegram></a> <a href=mailto:totufals@hotmail.com><img src=/img/mail.svg alt=Mail></a></div></footer></article><p class=abyss>Glaze into the abyss… Oh hi there!