O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering RethinkDB

Book Description

Master the capabilities of RethinkDB and implement them to develop efficient real-time web applications. The way to better database development is here!

About This Book

  • Master the powerful ReQL queries to manipulate your JSON data,
  • Learn how to develop scalable, real-time web applications using RethinkDB and Node.js and deploy them for production,
  • A detailed, step-by-step guide to help you master the concepts of RethinkDB programming with ease

Who This Book Is For

This book caters to all the real-time application developers looking forward to master their skills using RethinkDB. A basic understanding of RethinkDB and Node.js is essential to get the most out of this book.

What You Will Learn

  • Master the web-based management console for data-center configuration (sharding, replication, and more), database monitoring, and testing queries.
  • Run queries using the ReQL language
  • Perform Geospatial queries (such as finding all the documents with locations within 5km of a given point).
  • Deal with time series data, especially across various times zones.
  • Extending the functionality of RethinkDB and integrate it with third party libraries such as ElasticSearch to enhance our search

In Detail

RethinkDB has a lot of cool things to be excited about: ReQL (its readable,highly-functional syntax), cluster management, primitives for 21st century applications, and change-feeds. This book starts with a brief overview of the RethinkDB architecture and data modeling, and coverage of the advanced ReQL queries to work with JSON documents. Then, you will quickly jump to implementing these concepts in real-world scenarios, by building real-time applications on polling, data synchronization, share market, and the geospatial domain using RethinkDB and Node.js. You will also see how to tweak RethinkDB's capabilities to ensure faster data processing by exploring the sharding and replication techniques in depth.

Then, we will take you through the more advanced administration tasks as well as show you the various deployment techniques using PaaS, Docker, and Compose. By the time you have finished reading this book, you would have taken your knowledge of RethinkDB to the next level, and will be able to use the concepts in RethinkDB to develop efficient, real-time applications with ease.

Style and approach

This book is a unique blend of comprehensive theory and real-world examples to help you master RethinkDB.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Mastering RethinkDB
    1. Mastering RethinkDB
    2. Credits
    3. About the Author
    4. About the Reviewer
    5. www.PacktPub.com
      1. Why subscribe?
    6. Preface
      1. What this book covers
      2. What you need for this book 
      3. Who this book is for 
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    7. 1. The RethinkDB Architecture and Data Model
      1. RethinkDB architectural components
        1. Client drivers
        2. RethinkDB query engine
        3. RethinkDB clusters
        4. Pushing changes to a RethinkDB client
      2. Query execution in RethinkDB
      3. Filesystem and data storage
        1. About direct I/O
        2. Data storage
      4. Sharding and replication
        1. Sharding in RethinkDB
        2. Range-based sharding
        3. Replication in RethinkDB
        4. Indexing in RethinkDB
      5. Automatic failover handling in RethinkDB
      6. About voting replicas
      7. The RethinkDB data model
        1. RethinkDB data types
          1. Binary objects
          2. Geospatial queries in RethinkDB
          3. Supported data types
        2. RethinkDB model relationships
          1. Embedded arrays
            1. Merits of embedded arrays
            2. Demerits of embedded arrays
          2. Document linking in multiple tables
            1. Merits of document linking
            2. Demerits of document linking
      8. Constraints and limitation in RethinkDB
      9. Summary
    8. 2. RethinkDB Query Language
      1. Embedding ReQL in a programming language
        1. Performing CRUD operations using RethinkDB and Node
          1. Creating new records
          2. Reading the document data
          3. Updating the document
          4. Deleting the document
      2. ReQL queries are chainable
      3. ReQL queries are executed on a server
      4. Performing conditional queries
      5. Performing string operations
      6. Performing MapReduce operations
        1. Grouping the data
        2. Counting the data
        3. Sum
        4. Avg
        5. Min and Max
        6. Distinct
        7. Contains
        8. Map and reduce
      7. Calling HTTP APIs using ReQL
      8. Handling binary objects
      9. Performing JOINS
      10. Accessing changefeed (real-time feed) in RethinkDB
        1. Applications of changefeed
      11. Performing geolocation operations
        1. Storing a coordinate
        2. Finding the distance between points
      12. Performing administrative operations
      13. Summary
    9. 3. Data Exploration Using RethinkDB
      1. Generating mock data
        1. Importing data in RethinkDB using HTTP
        2. Importing data via file read
      2. Executing data exploration use cases
        1. Finding duplicate elements
        2. Finding the list of countries
        3. Finding the top 10 employees with the highest salary
        4. Displaying employee records with a specific name and location
        5. Finding employees living in Russia with a salary less than 50,000 dollars
        6. Finding employees with a constant contact e-mail address
        7. Finding employees who use class a C IP address
      3. Summary
    10. 4. Performance Tuning in RethinkDB
      1. Clustering
      2. Creating and handling a RethinkDB cluster
        1. Creating a RethinkDB cluster in the same machine
        2. Creating a RethinkDB cluster using different machines
        3. Creating a RethinkDB cluster in production
      3. Securing our RethinkDB cluster
        1. Using transport layer security
        2. Binding the web administrative port
      4. Executing ReQL queries in a cluster
      5. Performing replication of tables in RethinkDB
      6. Sharding the table to scale the database
      7. Running a RethinkDB proxy node
      8. Optimizing query performance
      9. Summary
    11. 5. Administration and Troubleshooting Tasks in RethinkDB
      1. Understanding access controls and permission in RethinkDB
        1. RethinkDB user management
      2. Failover handling in RethinkDB
      3. Performing a manual and automatic backup in RethinkDB
        1. Performing automatic backups
        2. Restoring a RethinkDB database
      4. Data import and export in RethinkDB
        1. Importing data from MySQL to RethinkDB
        2. Importing data from MongoDB to RethinkDB
        3. Data migration to an updated version
      5. Crash recovery in RethinkDB
      6. Using third-party tools
        1. ReQLPro
        2. Chateau
      7. Summary
    12. 6. RethinkDB Deployment
      1. Deploying RethinkDB using PaaS services
        1. Deploying RethinkDB on AWS
        2. Deploying RethinkDB on Compose.io
        3. Deploying RethinkDB on DigitalOcean
      2. Deploying RethinkDB using Docker
        1. The need for Docker
        2. Installing Docker
        3. Creating a Docker image
        4. Deploying the Docker image
      3. Deploying RethinkDB on a standalone server
      4. Summary
    13. 7. Extending RethinkDB
      1. Integrating RethinkDB with ElasticSearch
        1. Introducing ElasticSearch
        2. Installing ElasticSearch
        3. Performing operations in ElasticSearch
        4. The problem statement
        5. Integration use cases
          1. Search engine
          2. Static website search
      2. Integrating RethinkDB with RabbitMQ
        1. Installing RabbitMQ
        2. Developing producer code
          1. Connecting to the RethinkDB instance
          2. Creating a database and table if they do not exist
          3. Connecting to RabbitMQ
          4. Creating a channel and queue
          5. Attaching a changefeed and integrating the RabbitMQ queue
        3. Developing the consumer code
          1. Connecting to RabbitMQ
          2. Creating a channel and binding the queue
      3. Understanding the RethinkDB protocol
      4. Third-party libraries and tools
      5. Summary
    14. 8. Full Stack Development with RethinkDB
      1. Project structure
      2. Data modeling for our application
      3. Creating a Node.js server and routes
      4. Integrating RethinkDB with Node.js
      5. Integrating AngularJS in the frontend
      6. Socket.io integration for message broadcasting
      7. Summary
    15. 9. Polyglot Persistence Using RethinkDB
      1. Introducing Polyglot Persistence
      2. Using the RethinkDB changefeed as a Polyglot agent
      3. Developing a proof-of-concept application with MongoDB and MySQL
        1. Setting up the project
        2. Developing a server using Express
          1. Case - reading all users' data
          2. Case - creating a new user
          3. Case - updating user data
          4. Case - deleting the user
      4. Developing the Polyglot agent
      5. Developing event consumers
        1. Observer pattern
        2. MySQL consumer
        3. MongoDB consumer
      6. Running the app
      7. Further improvements
        1. Integrating the message broker
        2. Developing a distributed transaction
      8. Summary
    16. 10. Using RethinkDB and Horizon
      1. Workings of Horizon
      2. Installing and configuring Horizon
        1. Class Horizon
          1. Connect()
        2. Collection class
          1. Method subscribe()
          2. Watch method
          3. CRUD methods
      3. Developing a simple web application using Horizon
        1. Setting up the project
        2. Developing the JavaScript code
        3. Developing the frontend
      4. Horizon user management
      5. Summary