# NewSQL Databases Assessment: CockroachDB, MariaDB Xpand, and VoltDB
## 4 NewSQL Databases: CockroachDB, MariaDB Xpand, and VoltDB
### CockroachDB  
CockroachDB is a scalable database management system that was built in 2014 to support demanding OLTP workloads while maintaining simultaneously strong consistency and high availability [28]. CockroachDB, as its name implies and according to its creators, is disaster-resistant through automatic replication and recovery mechanisms. CockroachDB is a distributed relational database that scales without much effort, which is consistent with ACID transactions and provides a traditional SQL API for structuring, manipulating, and querying data [29]. Moreover, this database was built on a consistent key-value store, with crash recovery capabilities, and offers horizontal scalability, present in many NoSQL applications.  
CockroachDB's architecture is designed in layers to make it easier to manage. Figure 1 shows a diagram of its architecture [30].  
CockroachDB is divided into layers, and each one has the following functionalities:  
* SQL Layer: The highest level of abstraction for developers. This layer adds support for a wide range of SQL expressions and syntax from PostgreSQL libraries, with some modifications;
* Distributed Key-Value Store: This layer was implemented as a monolithic sorted map, allowing to run multiple computers in parallel, being able to work with larger datasets;
* Distributed Transactions: It is not necessarily considered a part of the layered architecture, but a necessary component of the system. Implementing distributed transactions allows to connect the layers of the architecture: from SQL to stores and ranges on each node;  
Figure 1: CockroachDB architecture diagram.  
* Nodes: They are mostly considered as physical machines, virtual machines, or containers that include stores. The distributed key-value (KV) store routes messages to nodes;
* Store: Each node in the database can contain one or more shops, and in turn, each shop can contain many ranges;
* Range: Ranges are the lowest-level unit of key-value data and every store contains ranges. Each range is used to sort items in specific partitions within the store, using the Raft consensus algorithm. The Raft algorithm is a variant of Paxos, which corresponds to a family of protocols that solves consensus in a network of unreliable processors.  
Figure 2 shows an example of three nodes running in a cluster, having access to the CockroachDB web user interface (UI).  
The main advantages of CockroachDB are [31]:  
* Cockroach offers customer support with migrations from other databases, as well as helping users with difficulties in using this database;
* CockroachDB can be used anywhere. It can be deployed in virtual machines, containers, Amazon web services, and many other applications;
* CockroachDB maintains data integrity and is able to survive crashes, due to the use of ACID properties;
* CockroachDB offers high performance and availability;
* CockroachDB scales horizontally and offers cloud support;
* CockroachDB has extensive documentation and tutorials guides;
* Supports PostgreSQL libraries to make use of SQL commands. The main limitations are the following [32]:  
* CockroachDB does not support database transactions with high complexity, since this database's purpose is speed;
* To make full use of CockroachDB, we need to pay for the enterprise version, whereas the core version can be used for most purposes with several functionality restrictions;
* Multi-region tables cannot be restored into tables that are not multi-region tables;
* SQL statements comprising numerous subqueries modifying the same table can cause corruption;
* CockroachDB does not support the use of RESTORE with multi-region table localities;
* The SET command, which allows modifying one of the session configuration variables, does not ROLLBACK in a transaction;
* JSONB/JSON comparison operators are not implemented.  
Figure 2: CockroachDB v21.2.10 web user interface cluster.  
Overall, CockroachDB is a database that has several functionalities, which allows working with a large data volume and scale without much effort.