Using Node.js with ScyllaDB

Web applications typically feed information back and forth from a database to process information for the user. Organizations need to build applications that can scale with their business. While it is easy to scale web applications with containers and cloud platforms, the last thing that an IT administrator would want is a bottleneck at the database because it would affect application performance and availability at scale. One way to address these concerns is by using a clustered database solution such as ScyllaDB. This blog post will demonstrate how to use Node.js and ScyllaDB running in Docker.

ScyllaDB is an open-source NoSQL database built on the Cassandra design. Scylla has a shared-nothing, thread-per-core design. You get best of all worlds: the scale-out, fault tolerance of Cassandra, with the throughput of a million operations per node and low and consistent latency.” – ScyllaDB Home Page

To get started, please install the latest version of Node.js and then  run the official ScyllaDB Docker image:

docker run --name some-scylla -d -p 9042:9042 --name scylla scylladb/scylla

The above command will start the container and listen on the IP address of the machine running the container to provide connectivity with the sample applications in the proceeding sections of this blog post.

Next, please download and extract it. The code is also available on GitHub. The zip archive will contain four files:

  1. createKeyspace.js – Creates the sample keyspace and data table.
  2. displayKeyspace.js – Displays the entries in the sample keyspace’s tables.
  3. metadata-hosts.js – Displays the hosts in the ScyllaDB cluster. This is from the DataStax Node.js driver page.
  4. package.json – Node Module reference for the sample application.

From the terminal, navigate to the extracted scylladb-node-examples directory and install the Node.js modules with:

npm install

Now we can run the first application that creates the keyspace, tables, and  sample data

node createKeyspace.js

To view the data entries, run the following command:

node displayKeyspace.js

The output should be:

ID: 3 Value: c
ID: 2 Value: b
ID: 1 Value: a

Now let’s look at the nodes in the cluster by running the following:

node metadata-hosts.js
Connected to cluster with 1 host(s): %j
Host v2.2.8 on rack rack1, dc datacenter1
Shutting down

Since this is only a single node setup, there is only one host listed.

I hope that these sample applications will help you get started with developing wonderful applications that use ScyllaDB. With Scylla’s scale-out architecture, your applications will be able to scale according to your business needs. If you have any questions, please reach out to me on Twitter.