Getting started with RethinkDB

RethinkDB is open source document based database system designed for developing real-time application. RethinkDB revolutionise the way data flows in real-time application. Generally, in order to know the changes in data we do check the database by performing polling in specific interval and if we find any changes we broadcast it to all connected nodes or specific connected nodes which we covered in these tutorials.

There are 3 important phases in real-time web application :

  1. Pull all data from model and show it to client.
  2. Keep checking for the changes in model ( Polling )
  3. If changes found notify to connected clients. ( Probably using Socket )

RethinkDB takes out step number 2 and provides us the real-time changes itself. So with RethinkDB as a model, here are the following steps we need to do build real-time web application.

  1. Pull all data from model and show to client.
  2. If there is changes, RethinkDB will notify the middle layer, broadcast them to client using Socket.

One of the biggest headache to any developer is the Step 2 only because it’s the heart of the real-time web application to know the changes in model. And if we deep down to more technical terms other than developer headache, then it puts a lot of loads to Server and latency of course increase ( By polling to Server requires various HTTP calls over Wide area network ).

Installing RethinkDB

You need to perform installation in two parts :

  • Installing RethinkDB Server.
  • Installing RethinkDB Client Driver.

RethinkDB Server is available for all major operating system, you can visit to their official website in order to know the supported platforms.

RethinkDB official client drivers are available for JavaScript, Ruby, Python, Java. There is community supported drivers available for C++, C#, R etc.

Installing in Linux (Ubuntu 14.10)

Run following command one by one to install the RethinkDB Server.

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

Install in Mac

Go to this link and download the installer file. If you have brew installed then you can directly install the RethinkDB Server in your system using following command.

brew update && brew install rethinkdb

Install in Window

Windows installer is still in beta. You can download the installer from here and follow the wizard to complete the installation.

Starting RethinkDB Server

Assuming you have installed RethinkDB in your machine. Open up new terminal and type following command to start the RethinkDB Server.

rethinkdb

rethinkdb server

Installing Node.js driver

Start a new Node.js project and create package.json file. Recommended way to create is using

npm init

command.
Run following command to install rethinkdb client driver.

npm install --save rethinkdb

About ReQL ( RethinkDB Query language )

ReQL query language let’s you manipulate and perform query on JSON document. Unlike other query languages, ReQL is chain-able and it embeds in programming languages. ReQL also let’s you perform sub queries over JSON document. This is rich and future of big data query processing. You can learn all the commands in details by visiting here.

Admin screen

Rethinkdb provides web administrative panel for the monitoring and management purpose. By using this web panel you can manage your server cluster, perform sharding and replication, check out logs and many more. To access the web console add following parameter when starting up rethinkdb Server.

rethinkdb --bind all

You should see following screen after executing the command.

Node and RethinkDB

Open http://localhost:8080 in your browser to access the web management console.

Node and Rethinkdb

What’s next ?

This post was intended to get you through installation and concept of RethinkDB. In next tutorial, we will be developing fully fledged real-time web application using Node and RethinkDB, so stay tuned.

Conclusion

RethinkDB is the future of real-time web application. With its query language, real-time feed change, scale-ability, it looks so promising. Also it is second rated in Github after Redis in database section.

Shahid
Shahid

Founder of Codeforgeek. Technologist. Published Author. Engineer. Content Creator. Teaching Everything I learn!

Articles: 126