Why RethinkDB, and why now

Most databases make you ask for changes. RethinkDB tells you about them. That single idea, pushing live query results to your application the moment data changes, is what makes RethinkDB worth a fresh look, and it is the focus of our upcoming demonstration.

In this post we set the stage. We cover what RethinkDB is, why FlyingFlip maintains its own Docker image of RethinkDB 2.4.4, and how to get a server running on your machine in under a minute. When the demo arrives, you will be ready to follow along.

What is RethinkDB?

RethinkDB is an open-source, distributed NoSQL database that stores JSON documents and scales out across multiple machines. It is easy to set up, and its query language, ReQL, is expressive enough to handle joins, groupings, aggregations and functions.

A few features set it apart from other document stores:

  • Changefeeds. Subscribe to a table, a single document or even a filtered query, and RethinkDB streams every change to your app in real time. No polling, no separate message broker.
  • ReQL is chainable and embedded. Queries are built in your host language (JavaScript, Python, Java, Ruby and more) by chaining methods, so they read like code rather than strings.
  • Joins and aggregations. Unlike many NoSQL databases, RethinkDB supports table joins, group, reduce and map-reduce operations natively.
  • Clustering built in. Sharding and replication are configured per table, and the web admin UI lets you manage a cluster without touching a config file.

Here is a taste of ReQL in JavaScript, subscribing to every new high-priority order:

RethinkDB ReQL Sample JavaScript
const r = require('rethinkdb');
const conn = await r.connect({ host: 'localhost', port: 28015 });

const cursor = await r.db('shop').table('orders')
  .filter({ priority: 'high' })
  .changes()
  .run(conn);

cursor.each((err, change) => console.log(change.new_val));

That is a live, push-based query in about ten lines. This is the pattern that makes RethinkDB a natural fit for dashboards, chat, collaborative editing and any UI built with React or Next.js that needs to reflect data the moment it changes.

The FlyingFlip RethinkDB image

FlyingFlip publishes flyingflip/rethinkdb on Docker Hub as a drop-in replacement for the official RethinkDB image. It runs the same RethinkDB 2.4.4 server, exposes the same ports and uses the same /data volume, so the official documentation still applies.

We built it to close two gaps in the official image:

  • Native ARM64 support. Upstream RethinkDB ships only amd64 builds. Our image is published for both arm64 and amd64, so it runs natively on Apple Silicon Macs, Raspberry Pi-class boards and ARM cloud instances. The ARM build is community supported, so use it at your own discretion.
  • Backup and data tools included. The official image leaves out the RethinkDB Python tools. Ours ships rethinkdb-dump, rethinkdb-restore, rethinkdb-export, rethinkdb-import, rethinkdb-index-rebuild and rethinkdb-repl, ready to run with docker exec.

Under the hood, the image is built on Alpine Linux 3.22 with RethinkDB compiled from source. The source and Dockerfile are on GitHub.

TagArchitecture
2.4.4, latestMulti-arch: pulls arm64 or amd64 to match your CPU
2.4.4-arm (also 2.4.1 to 2.4.3)arm64 only
2.4.4-amd (also 2.4.1 to 2.4.3)amd64 only

Quick start: RethinkDB running in one command

If you have Docker installed, this is all it takes:

RethinkDB Start With One Command Bash
docker run --name rethinkdb -p 8080:8080 -p 28015:28015 -d -v "$PWD:/data" flyingflip/rethinkdb

Open http://localhost:8080 and you will see the RethinkDB web admin UI, complete with a Data Explorer for running ReQL queries interactively. Your application drivers connect on port 28015.

The container's default command is rethinkdb --bind all, so the server listens on every interface inside the container. Without that flag, RethinkDB only accepts localhost connections and would be unreachable from your host. Data is written to /data; mounting a directory or named volume there keeps your data when the container is removed.

PortPurpose
8080Web administration UI
28015Client driver connections
29015Intracluster connections between servers

Prefer Docker Compose? Here is a setup with port mapping that we will build on in the demo:

RethinkDB Docker Compose YAML
services:
  rethinkdb:
    image: flyingflip/rethinkdb
    container_name: rethinkdb
    volumes:
      - ./data:/data
    ports:
      - "8080:8080"
      - "28015:28015"
    networks:
      - rethinkdb
    restart: unless-stopped
networks:
  rethinkdb: {}

Need custom server flags, such as a larger cache? The binary lives at /opt/bin/rethinkdb and is not on the container's PATH, so use the full path and keep --bind all:

RethinkDB Custom Server Flags Bash
docker run --name rethinkdb -p 8080:8080 -d -v "$PWD:/data" flyingflip/rethinkdb \
  /opt/bin/rethinkdb --bind all --cache-size 2048

Backups without extra setup

Because the Python tools ship inside the image at /root/.local/bin, backing up every database is a single docker exec. Writing the archive under /data lands it on your mounted volume, so it is available on the host:

RethinkDB Export Database Bash
docker exec rethinkdb /root/.local/bin/rethinkdb-dump -c localhost:28015 -f /data/backup.tar.gz

Restoring is just as short:

RethinkDB Import Database Bash
docker exec rethinkdb /root/.local/bin/rethinkdb-restore -c localhost:28015 --force /data/backup.tar.gz

If you have set an admin password, add -p to be prompted for it. rethinkdb-export and rethinkdb-import work the same way for moving individual tables in and out as JSON.

A note for Apple Silicon users

RethinkDB does not run under CPU emulation. On an Apple Silicon Mac, the amd64 image (and the official rethinkdb image) hangs at startup under Docker Desktop's emulation. Use the latest or 2.4.4 tag, which pulls the native arm64 build automatically, or pin a -arm tag.

Coming up in the demo

With a server running, you are ready for the hands-on part. In the demonstration we will:

  1. Create a database and tables from the Data Explorer and from code.
  2. Write ReQL queries, including filters, joins and aggregations.
  3. Wire up a changefeed and watch a live UI update as data changes.
  4. Back up and restore the data with the bundled tools.

Pull the image now with docker pull flyingflip/rethinkdb so you can follow along.

Resources