DEV Community

João Victor Martins
João Victor Martins

Posted on

Working with Scylla Database

Hello everyone! My intention today is to write about Scylla database. Scylla is a NoSQL database based on Cassandra. One difference between both is that Cassandra is developed in Java language and Scylla in C++ language. The goal of that is to avoid some Java processes that can impact the performance of the application, like garbage collector and stop the world. After this introduction, let's see how we can use Scylla and know some details about it.

Downloading image

For work with Scylla, we will use docker. The first step is to download the image. We can use the command below.

docker run --name scylla-db-test -d scylladb/scylla:4.1.0
Enter fullscreen mode Exit fullscreen mode

After that, we can use some tools of Scylla and guarantee that our database is healthy.

docker exec -it scylla-db-test nodetool status
Enter fullscreen mode Exit fullscreen mode

The result of executing the command above is

Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address     Load       Tokens       Owns    Host ID                               Rack
UN  172.17.0.2  866.47 KB  256          ?       0b8a4db2-b8ea-49cf-b618-4eaf780ba7c7  rack1
Enter fullscreen mode Exit fullscreen mode

There is information about Datacenter, but this is not our focus in this post. At this moment, we should just know that our node (more information about that in the next section) is Up and Normal (UN).

Playtime

For executing commands in Scylla, there is a CLI called cqlsh.

docker exec -it scylla-db-test cqlsh

Connected to at 172.17.0.2:9042.
[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.3.1 | Native protocol v4]
Use HELP for help.
cqlsh> 
Enter fullscreen mode Exit fullscreen mode

The first thing that we can do is create a keyspace. Different from relational databases, Scylla doesn't have the database concept. In Scylla we work with keyspace, which is a top-level container that stores tables. Besides creating a keyspace, we need to configure other attributes like replication strategy.

CREATE KEYSPACE automobiles WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};
Enter fullscreen mode Exit fullscreen mode

Like I said previously, it's necessary to configure replication strategy and how we can see, this is done with attribute replication. Inside brackets has two configurations. The replication_factor which means that the data inserted in a table of automobiles keyspace will be replicated in 3 nodes. Nodes are instances of Scylla DB. The other configuration is class and defines the replication strategy class to use. There are 2 options:

'SimpleStrategy': defines a replication factor for the whole cluster. The only sub-options supported is 'replication_factor' to define that replication factor and is mandatory.

'NetworkTopologyStrategy': A replication strategy that lets you set the replication factor independently for each data center. The rest of the sub-options are key-value pairs where a key is a data-center name and its value is the associated replication factor or a single key-value with Auto-Expand Replication Factor. Recommended for production. (Just for knowledge, we won't talk about this option in this post)

Now we can create our table. The name will be Car.

USE automobiles ;

CREATE TABLE car (id uuid, brand text, model text, color text, PRIMARY KEY(id)) ;
Enter fullscreen mode Exit fullscreen mode

How we can see, Scylla syntax is similar to SQL syntax, and to include data, we use the insert clause.

INSERT INTO car (id, brand, color, model) VALUES (123e4567-e89b-12d3-a456-426614174000, 'VW', 'Red', 'Golf');
Enter fullscreen mode Exit fullscreen mode

To see data in the table is just necessary to use the select clause.

SELECT * FROM car;

 id                                   | brand | color | model
--------------------------------------+-------+-------+-------
 123e4567-e89b-12d3-a456-426614174000 |    VW |   Red |  Golf
Enter fullscreen mode Exit fullscreen mode

Conclusion

The idea of this post is to presenting Scylla DB and some operations that we can do. There are more details that I intended to present in the future, as partition key and clustering key, and how we can define our primary key mixing up of both concepts. This is crucial for better performance at the moment that we need to filter our searches. For now, that is enough. I will see you in the next post.

References
https://docs.scylladb.com/getting-started/dml/
https://university.scylladb.com/

Top comments (10)

Collapse
 
marcuspaulo profile image
Marcus Paulo

Excellent post! Congratulations João.

Collapse
 
j_a_o_v_c_t_r profile image
João Victor Martins

Thank`s man!!

Collapse
 
dearrudam profile image
Maximillian Arruda

Awesome post! Congratulations João! I’ve listened about Scylla DB already but I never tried it... I’m curious about it now! Thanks sharing!

Collapse
 
j_a_o_v_c_t_r profile image
João Victor Martins

Thank`s Max. You are awesome.

Collapse
 
paulo_iggor profile image
Paulo Igor

Amazing!!!

Collapse
 
j_a_o_v_c_t_r profile image
João Victor Martins

Thank`s man!!

Collapse
 
magmoura1 profile image
Mag Moura

Excelente explanação!

Collapse
 
j_a_o_v_c_t_r profile image
João Victor Martins

Thank you!!

Collapse
 
freeluke_ profile image
Lukas Henrique

Great Job!! Very easy reading!

Collapse
 
j_a_o_v_c_t_r profile image
João Victor Martins

Thank`s man!!