Cassandra Spring Implementation

Cassandra is a distributed NoSQL database. Cassandra is developed with java. Cassandra is highly popular because of some technical reasons such as scalability, its distributed structure that can support multi datacenter, keeping data at very high size, very high reading and writing speed. Companies such as Facebook, Twitter and Cisco use this database.

Basic Features of Cassandra

Horizontal Scalability :

Cassandra allows to increase capacity by adding new servers in the cluster. It has nearly linear scaling performance. Therefore Cassandra guarantees high performance.

No Single Point of Failure :

Because Cassandra is designed to provide continuous accessibility, it is not possible for the conglomerate to fail because of a server error. It does not use “master / slave” or replication structures in classic databases. The data are distributed to the nodes in the cluster. It is copied to the server in the desired number (replication factor). Since all servers are designed to respond to incoming requests, the problem with one of the servers will not affect the whole cluster.

Replication :

Every server in the cluster can respond to reading and writing requests. The first server the request comes in is called the “coordinator” and allows copying for the desired number of servers. The number of the copies (Replication Factor) can be set in the database.

Consistency Levels :

This level determines how many servers will receive the read request and how many requests will be returned to the client after the data is written to the client “completed”.

The level of data consistency in the Cassandra database can be set on a cluster and query basis. High data consistency level negatively affects performance. For this reason, it will be correct to adjust it appropriately.

The codes belong to spring part are given as follows.

DevBootstrap
DevBootstrap
DevBootstrap
DevBootstrap
DevBootstrap
DevBootstrap
DevBootstrap
DevBootstrap
DevBootstrap
DevBootstrap
DevBootstrap
DevBootstrap
DevBootstrap

Before running this spring application, first of all, Cassandrahas to be up and running. To do this, open the terminal and write as follows.

docker pull cassandra
DevBootstrap

After that, write

docker run -p 9042:9042 --rm --name cassandra -d cassandra

DevBootstrap

To open cql, write following commands.

docker run -it --link cassandra:cassandra --rm cassandra cqlsh cassandra
DevBootstrap

To create a keyspace,

CREATE KEYSPACE mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };

To create table and indexes,

DevBootstrap
DevBootstrap

After all steps, run the project and open web browser and write localhost:8080. Here is the example.

DevBootstrap