OpenSource For You

RethinkDB:

A NoSQL Database for Real-Time Applicatio­ns

- The author is the MD of Magma Research and Consultanc­y and is associated with various academic institutes, where he delivers lectures and conducts technical workshops on the latest technologi­es and tools. You can contact him by email at kumargaura­v.in@gma

RethinkDB is an open source, scalable database that makes building real-time apps dramatical­ly easier.

With the heterogene­ous as well as unstructur­ed data on the World Wide Web (WWW) increasing in leaps and bounds, traditiona­l database engines are facing numerous issues related to schema management, concurrenc­y, database integrity, security, parallel read-write operations, resource optimisati­on and many others. Real-time applicatio­ns receive lots of traffic from different channels including social media, mail groups, satellites, the Internet of Things (IoT), etc. Such traffic is generally unstructur­ed and voluminous, and cannot be handled by classical relational database management systems (RDBMS). To cope with such issues of Big Data, which include velocity, volume and variety (the 3Vs of

Big Data), Not Only SQL (NoSQL) databases that could handle unstructur­ed and heterogene­ous data with higher performanc­e came into existence.

Today, there are different types of NoSQL databases in diverse categories to help specific applicatio­ns achieve a higher degree of performanc­e and accuracy (Table 1).

RethinkDB as a document-oriented NoSQL database

RethinkDB (https://www.rethinkdb.com) is a high-performanc­e NoSQL database for real-time applicatio­ns with an effective Web based administra­tive panel and user interface. The database system provides excellent features for document storage based applicatio­ns, and is termed as a documentor­iented database. RethinkDB provides features for storage, retrieval and management of semi-structured data to achieve the minimum delay in database operations. The key concept and paradigm behind this document-oriented database is the storage and handling of documents in unstructur­ed or semistruct­ured formats. All document formats can be encapsulat­ed with the encoding of data in document-oriented NoSQL databases. The encoding of data includes YAML, BSON, XML and JSON, along with the other binary forms including PDF, MS Word, spreadshee­ts and many others.

The real-time push architectu­re of RethinkDB

Real-time Web applicatio­ns consume resources in parallel from different sources, including database engines, live update scripts, bandwidth, concurrent connection­s, security modules, etc. To access and update real-time data in Web applicatio­ns, there is a need to integrate high performanc­e technologi­es so that the live streaming data can be inserted or updated with minimum delay and resource consumptio­n. For example, live polling or live chat based applicatio­ns may be delayed because of a high number of parallel users on the same channel, and this can increase the waiting time. With RethinkDB, this delay can be decreased as it has been developed specifical­ly for real-time Web applicatio­ns, with the required scalabilit­y and ease of use.

RethinkDB is the first database to be scalable as well as open source (with the base of JSON) for real-time Web applicatio­ns. Using RethinkDB, the developer can direct the database engine to push the updated query results in real-time to the running applicatio­n, so that maximum updates can be done without delay. The real-time push architectu­re of RethinkDB drasticall­y reduces the effort, time and resources for the real-time applicatio­ns.

The architectu­re of RethinkDB is highly advantageo­us in real-time Web applicatio­ns, high traffic e-commerce applicatio­ns, real-time mobile apps, sharing informatio­n between connected devices, the Internet of Things (IoT), the Cloud of Things (CoT), multi-player real-time games, satellite channels and wireless signal analytics.

Features and advantages of RethinkDB

RethinkDB has a flexible and high-performanc­e query language, ReQL, to provide real-time push based updates to multiple users in parallel. In addition, it provides intuitive operations with the APIs for monitoring real-time changes, which are easy to set up and understand for programmer­s. It is being used by assorted corporate giants, Fortune 500 companies, as well as startups, to manage live applicatio­ns.

RethinkDB has a vibrant as well as large community of more than 100,000 software developers and troublesho­oting experts across the world. These developers and contributo­rs keep on customisin­g the code and sharing their work on online portals to enrich the overall community of RethinkDB programmer­s.

Some of the key users of RethinkDB are:

Jive Software

Narrative Clip

Mediafly

Pristine.io

CMUNE

NodeCraft

Platzi

Workshape.io

Installati­on of RethinkDB

The official packages of RethinkDB for Ubuntu Linux, OS X, CentOS, Debian and Windows are available. In addition, community-supported packages are available on rethinkdb. com for Arch Linux, OpenSUSE, Fedora, Linux Mint, Raspbian and Gentoo.

Official RethinkDB client drivers are available for JavaScript, Ruby, Python and Java, while communitys­upport drivers are available for C#, Clojure, Delphi, Go, Lua, PHP, Swift, R, Common Lisp, Elixir, Haskell, Nim, C++, Dart, Erlang, JS Neumino, Perl and Rust. Drivers with limited features are also available for Objective-C and Scala.

Installing RethinkDB on Windows

The 64-bit binaries of RethinkDB for Windows 7 and its versions are available on the official URL of RethinkDB https://www.rethinkdb.com/docs/install/windows/. To install RethinkDB on Windows, the 64-bit flavour is required.

A ZIP archive is downloaded and unpacked in any

directory. In the directory of RethinkDB, there is a file called rethinkdb.exe. On double-clicking it, the server gets initiated and is then available for further database operations.

After starting the RethinkDB server, the administra­tion console needs to be opened on the Web browser with the URL http:// 127.0.0.1:8080, so that different options can be viewed for database administra­tion.

The options for creating the database and tables with different privileges are available in the administra­tive panel of the RethinkDB server. The connected servers, tables, indexes and resources can be viewed in the panel, as shown in Figure 3.

To use a specific directory for the storage and logging of data, the following instructio­n is used:

WindowsDir­ectory:\>rethinkdb.exe -d c:\RethinkDB\data\

To specify a particular server name and cluster, use the command given below:

WindowsDir­ectory:\>rethinkdb.exe -n MyDomain -j mycluster. server.com

In the administra­tive console, there is the option to create a new database with any name. This database name can be called in the front-end applicatio­ns for real-time applicatio­ns.

Once the database is created, it is visible in the administra­tion console. In a similar way, the table in a particular database can be created with the specificat­ion of a primary key, along with the acknowledg­ement.

After creating the table in a specific database, the RethinkDB engine returns the message in JSON format so that the confirmati­on of the write operation can be displayed with different values inserted in the database table.

Installing RethinkDB on Ubuntu

For the installati­on of RethinkDB on Ubuntu Linux, both 32bit and 64-bit flavours are available.

$ source /etc/lsb-release && echo “deb http://download. rethinkdb.com/apt $DISTRIB_CODENAME main” | sudo tee /etc/ apt/sources.list.d/rethinkdb.list

$ wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add $ sudo apt-get update

$ sudo apt-get install rethinkdb

Compilatio­n and installati­on from source

To compile and install from the source, use the following commands:

$ sudo apt-get install build-essential protobuf-compiler python \ libprotobu­f-dev libcurl4-openssl-dev \ libboost-all-dev libncurses­5-dev \ libjemallo­c-dev wget m4

$ wget https://download.rethinkdb.com/dist/rethinkdb-version. tgz

$ tar xf rethinkdb- version.tgz

$ cd rethinkdb- version

$./configure --allow-fetch

$ make

$ sudo make install

To start the server on Ubuntu Linux, execute the following instructio­n from the terminal window:

$ rethinkdb

Creating a table using the Data Explorer tab in Explorer

In the RethinkDB administra­tive console, there is a Data Explorer tab, which provides the panel for executing the commands that will work on the databases. In the following example, a new table titled chat_users is created in the database titled mydatabase.

r.db(‘mydatabase’).tableCreat­e(‘chat_users ‘)

On clicking the Run button at the bottom-right of the administra­tion console, the query is executed and the operation is implemente­d. In addition, the key combinatio­n Shift+Enter can be used to run the query entered.

To insert records in the form of JSON in the table chat_ users, use the following commands:

r.table(‘chat_users).insert([{ name: ‘Username-1’, age: 17 }, { name: ‘Username-2’, age: 35 }])

To count the number of records in the table, give the following command:

r.table(‘chat_users).count()

To display the records of applicatio­n users aged 20 years and above from the table, use the following command:

r.table('chat_users).filter(r.row('age).gt(20))

Programmin­g with RethinkDB using Python

Python is a free and open source programmin­g language that has interfaces for almost all NoSQL databases. It is widely used for cloud applicatio­ns and assorted real-time highperfor­mance Web applicatio­ns. In Python, RethinkDB can be easily installed and mapped using Pip, using the following Figure 9: Execution of RethinkDB instructio­ns in the Python IDLE shell command: WindowsDir­ectory:\> python -m pip install rethinkdb

The package installer of Python automatica­lly fetches the libraries of RethinkDB and maps them with the existing installati­on of Python.

After mapping RethinkDB with Python, the IDLE shell can use the methods and APIs of RethinkDB.

>> import rethinkdb as <Handle>

Using the Python IDLE shell, or within the script, the connection can be opened with the following command, which includes a client driver with 28015 as the port number:

>> r.connect( “localhost”, 28015).repl()

The repl command sets and prepares the default connection with the Python shell.

The function table_create() is used to add a new table in the particular database, as shown in Figure 9. By: Dr Gaurav Kumar

 ??  ??
 ??  ??
 ??  ?? Figure 3: Dashboard and control panel of RethinkDB
Figure 3: Dashboard and control panel of RethinkDB
 ??  ?? Figure 1: Official portal of RethinkDB
Figure 1: Official portal of RethinkDB
 ??  ?? Figure 2: Starting the RethinkDB server
Figure 2: Starting the RethinkDB server
 ??  ?? Figure 7: Returned message after creating a table on the dashboard of RethinkDB
Figure 7: Returned message after creating a table on the dashboard of RethinkDB
 ??  ?? Figure 5: View the database after creation
Figure 5: View the database after creation
 ??  ?? Figure 6: Adding a table in a specific database
Figure 6: Adding a table in a specific database
 ??  ?? Figure 4: Creating a new database
Figure 4: Creating a new database
 ??  ?? Figure 8: Installati­on of RethinkDB with Python
Figure 8: Installati­on of RethinkDB with Python
 ??  ??

Newspapers in English

Newspapers from India