S101: ScyllaDB Essentials

 · 8 mins read

I wanted to learn a bit more about ScyllaDB given I’ve been hearing some great things about it.

Motivation

I got some fun swag!!

scyllau-selfie

Context

My company is also an early adapter of ScyllaDB and as a result, I’ve gotten to explore and play around with it some.

We’re also big consumers of Go and given that Go is a statically typed language, I wanted to build out some more support for the interaction between Scylla and Go. I’ll hopefully be writing about that in the future when I get things in a more publishable state.

Initial Introduction

I had previously worked some with NoSQL databases like Cassandra (of which Scylla is basically a descendant), but not to the degree that I have been doing recently.

As a result, I thought it would be best to go through the formal 0 -> 1 training from their tutorials and educational videos. So I jumped over to Scylla University and took their

S101 Class Notes

These aren’t the best notes, but I’d encourage pulling a docker image that has this set up and experimenting with the consistency level. Probably the best part of the class.

Class Notes:

# S101: ScyllaDB Essentials

- [S101: ScyllaDB Essentials](#s101-scylladb-essentials)
  - [Introduction](#introduction)
    - [Intro and Overview](#intro-and-overview)
    - [NoSQL and ScyllaDB Overview](#nosql-and-scylladb-overview)
    - [Design Decisions and ScyllaDB Flavors](#design-decisions-and-scylladb-flavors)
    - [Basic Concepts and Intro to Architecture](#basic-concepts-and-intro-to-architecture)
    - [The Read/Write Path](#the-readwrite-path)
  - [Quick Wins: Install and Run ScyllaDB](#quick-wins-install-and-run-scylladb)
  - [High Availability](#high-availability)
    - [Replication Factor](#replication-factor)
    - [Consistency Level](#consistency-level)
  - [Architecture](#architecture)

## Introduction

### Intro and Overview

Disney and other big companies are using it.

- 10x higher throughput compared to other dbs
- Up 10 1M r/w operations per node per second
- Compatible with Apache Cassandra and DynamoDB

### NoSQL and ScyllaDB Overview

- CAP Theorem
  - Distributed databases have 3 characteristics
    - **Consistency**
      - For the latest read request, we always get the latest write
    - **Availability**
      - Always able to serve requests despite hardware failures and whatever
    - **Partition Tolerance**
      - If there's a network failure, or node failures, we're still serving requests
  - ScyllaDB prefer Availability and Partition Tolerance
- NoSQL - By Data Model
  - Key/Value -> RocksDB, EroSpike, redis
  - Document store MongoDB, Couchbase
  - Wide column store -> ScyllaDB, cassandra, Amazon DynamoDB, Apache HBase
  - Graph -> JanusGraph, neo4j
- ScyllaDB Attributes
  - High availability
  - High scalability
  - High performance
  - Low maintenance
  - Drop in replacement, Cassandra DynamoDB

### Design Decisions and ScyllaDB Flavors

- Shard per Core model
  - ThreadPool model (Apacha Cassandra)
    - Thread is chosen whenever we have a job
    - Lots of context switching
    - Puppies eating from the same bowls, some bowls are left empty, etc
- Ecosystem Compatibility
  - Apache Cassandra is very popular
    - CQL native protocol
    - JMX mangaement
    - Management command line
    - SSTable file format
- Cost Effective
  - vs DynamoDB
    - 1/5th cost
    - 20x better latencies
  - vs Cassandra
    - 4 Scylla nodes vs 40 Cassandra nodes
    - 2.x less expensive
    - 11x better latencies
  - vs BigTable
    - 1/7th cost
    - 26x performance

### Basic Concepts and Intro to Architecture

- Basic Architecture - node
  - consists of shards
  - contains portion of DB content
  - all nodes are equal
- Cluster - node ring
  - 5 nodes for example working otgether
- Partition key
  - get a partition key, we hash, we then find which cluster to go to
  - and so we know which nodes are responsible
- **Token Ranges**
  - Each node is responsible for a range of tokens
  - Scylla knows which node is responsible for the data
  - As a user, that performs the query, we don't have to
- **Data Replication**
  - Replciation Factor: number of nodes where data (rows and partitions) are replicated
  - Done automatically
  - Set for keyspace
- **Consistency Level:**
  - CL: # of nodes that must acknowledge read/write
  - i.e. 1, QUORUM, LOCAL_QUORUM
  - Tunable consistency: CL set per operation

### The Read/Write Path

- Client makes a write request
- Coordinator node receives the data
- Example:
  - RF = 3
    - That means that each piece of data is replicated to three separate nodes
  - Consistency level = QUORUM
    - Requires that 2 / 3 nodes acknowledges that
  - Client sends request
  - Node V gets it
  - Node V executes the consistent hash
  - It knows which of the three nodes are responsible for the data
  - So there's this `write` -> `ack` communication
  -

## Quick Wins: Install and Run ScyllaDB

Done. Basically this:

╭─johnlarkin@Johns-MacBook-Pro ~
╰─➤ remindme-scylla-docker
Commands to run and mess around with cqlsh:
===========================================
docker run --name scyllaU -d scylladb/scylla:5.2.0 --overprovisioned 1 --smp 1
docker exec -it scyllaU nodetool status
docker exec -it scyllaU cqlsh

# Then once you're in the interactive shell:

CREATE KEYSPACE mykeyspace WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1};
use mykeyspace;
CREATE TABLE users ( user_id int, fname text, lname text, PRIMARY KEY((user_id)));
insert into users(user_id, fname, lname) values (1, 'rick', 'sanchez');
insert into users(user_id, fname, lname) values (4, 'rust', 'cohle');

## High Availability

### Replication Factor

Relatively straightforward. Sets how many copies of the data is made.

### Consistency Level

- Determines how many repliaces in a cluster must acknowledge a read or write operqation before its considered successful

Some common levels:

- `ANY`
  - A write must be written to at least one replica in the cluster
  - A read waits for a response from at least one replica
  - This provides the highest availability with the lowest consistency
- `QUORUM`
  - When a majority of the replicas respond, the request is honored
  - If `RF=3` then 2 replicas respond. `QUORUM` can be calculated using the formula (`n/2 + 1`) where `n` is the Replication Factor.
- `ONE`
  - If one replica responds, the request is honored
- `LOCAL_ONE`
  - At least one replica in the local data center responds
- `LOCAL_QUORUM`
  - A quorum of replicas in the local datacenter responds
- `EACH_QUORUM`
  - Unsupported for reads - a quorum of replicas in _all_ datacenters must be written to
- `ALL`
  - A write must be written to _all_ replicas in the cluster, a read waits for a response from all replicas. Provides teh lowest availability with the highest consistency

**Note:** A write it always sent to _all_ replicas, as set by the Replication Factor.

## Architecture

Just reviewed a lot of the material above.

Conclusion

The whole point of this post is this portion. ScyllaDB is great and I’ve been loving using it, but the best part is for sure that I chatted some with the instructor, Guy Shtub, begged him for a shirt (because I don’t have enough tech shirts), he said no, i begged harder, and then voila, get a good look:

scyllau-selfie