An Introduction to CockroachDB !!!


Hello Folks,

Today we are going to discuss about the Resilient SQL Database. As we know database is a main part for any organization or business.  We say that we have many databases in the present, developers are left with a small range of options:

  1. Traditional RDBMS:
    Traditional Database is known for the Transaction, Consistency and indexes, but are not scalable and fault-tolerant. As you business grows it will become hard for the developer to scale your business. If you want to make changes and increase number of nodes, you have to restore and shards your all data.
  2. NoSQL:
    NoSQL is designed for the large scale of data but for achieve the scalability, it sacrifice the Schema, Transaction and Consistency. It will not help to implement complex application.

As we can see that these options does not work properly when we have large amount of data, which is why we are inspired to talk about Cockroach DB.

CockroachDB is a distributed SQL database built on top of a transactional and consistent key-value store. The primary design goals are support for ACID transactions, horizontal scalability and survivability. CockroachDB implements a Raft consensus algorithm for consistency and aims to tolerate disk, machine, rack and even data center failures with minimal disruption and no manual intervention.

Architecture Of CockroachDB:

CockroachDB follows an architecture and make complexity an easier task to manage.

diagram

  1. SQL Layer: This layer is an highest level of abstraction and provide help to the developers to run SQL query. It provides all the familiar terms and concepts such as schema, tables and indexes.
  2. Distributed Key:Value Store: This is implemented on distributed key-value store, so that we can develop large tables and indexes as Hbase, BigTable etc.
  3. Distributed Transactions: Transaction is the core and fundamental part of the applications. The implementation of distributed transactions suffuse the layers of the architecture: from SQL to stores and ranges.
  4. Nodes: That place where we store or contains data. It could be the physical machines, virtual machine. The distributed KV store routes messages to nodes.
  5. Store: Each node contains one or more stores, and each store contains potentially many ranges. Every store is managed with RocksDB, an open source storage engine from Facebook based on Google’s LevelDB.
  6. Range: Every store contains ranges, which are the lowest-level unit of key-value data. Each range covers a contiguous segment of the larger key-space — one at the start of the alphabet, the next in the middle of the alphabet, and so on. Together, they make up the entire monolithic sorted map.

Replication:

By default each range replicate on three nodes. We can configure replication nodes according to the our need. When we use replication that time we have to make sure one and important thing, data be consistence on all the replicas. CockroachDB uses Raft as its consensus protocol. Raft consider as a singe entity for each range. Each Range corresponds to a Raft instance, and their number is much higher than that of the physical nodes hosting them.

Horizontal Scaling:

In CockroachDB, it stores data into tables, columns, rows and schema but at the lowest level, contains data into Key-Value pair. It contains single and empty range of key value. As you start storing data into range it reaches threshold and default size of the threshold is  64 MB. As it reaches on the maximum limit, range data split into two. Each of which can be accessed as a separate units, each covering a contiguous segment of the key space. CockroachDB stores data into sorted set of all ranges.

Distributed Transactions:

Transactions is the core functionality when we talk RDBMS and as we mention earlier CockroachDB provides distributed transactions using multi-version concurrency control(MVCC). MVCC data is stored and managed on each local storage device with an instance of Rocks DB. CockroachDB also provides snapshot and serialize snapshot along with consistency & lock free read and write.

So folks this is basic introduction for the CockroachDB where we discuss about the need of the CockroachDB and Architecture of  the CockroachDB.

Stay Tunned for more blogs on this !!!

If You have any questions you can comment me here or contact me on Twitter: @anuragknoldus

KNOLDUS-advt-sticker

This entry was posted in database, Scala and tagged , , , . Bookmark the permalink.

One Response to An Introduction to CockroachDB !!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s