Replication in RethinkDB

By default, RethinkDB will not replicate tables across nodes. With non-replicated tables, there's always the risk of data loss should a specific instance experience catastrophic failure. If you have data that is not currently replicated, the Compose UI will display a message:


The Deployment Topology with unreplicated tables.

To prevent data loss, you can manage replication a few different ways.

Enable Replication through the Administrative Console

Access your RethinkDB administration panel and head to the Tables page.


The Tables page in the RethinkDB Admin UI.

Click on table you'd like to replicate, and under the Sharding and replication heading you will see the current configuration along with a Reconfigure button.


Table overview showing the current table configuration settings.

Clicking on the Reconfigure button will allow you to set how many replicas you would like to make of your tables. Compose RethinkDB deployments come with 3 nodes, so you may replicate your data across all of them by setting your replica count to three.


Changing the sharding and replication settings.

Before updating the configuration, click on the Where's my data going? link to see how the data will be spread out. You can change the values in the shards and replicas per shard fields to see how that affects the underlying storage configuration for this table.

To save your new configuration, click on the Apply configuration button. The table will be temporarily unavailable while the replication is being carried out, but should come back quickly once it is finished.

After you adjust your sharding and replication details, you can ensure the data is being stored on multiple nodes by scrolling down on the Tables page. You'll see where your data is going such as this example which shows 1 shard with 3 replicas:


Topology of a replicated table.

Notice how the replicas are spread out across various places - if something happens on one node, your other replicas are safe and sound.

Enable Replication with ReQL

If you are using the Data Explorer (from the Administrative Console) or the command-line, language driver, and ReQL to manage your deployment, the reconfigure command will allow you to set the shards and replicas configuration on your table.

An example command to run from the Data Explorer:
r.db('examples').table('shows').reconfigure({shards: 1, replicas: 3})
Where examples is the database, and shows is the table that we would like to replicate.

More on the syntax of reconfigure with usage in different languages can be found in the ReQL reference.

Set Replication Settings on Table Creation

You may opt to program your application to configure replication at table creation by using the optional replicas parameter to tableCreate.

An example command to run from the Data Explorer to create a new table albums, in the database eighties, that you would like replicated across all 3 nodes would look like this:
r.db('eighties').tableCreate('albums', {replicas: 3})

More on the syntax of tableCreate with usage in different languages can be found in the ReQL reference.

Still Need Help?

If this article didn't solve things, summon a human and get some help!