CouchDB Data Replication

Shivaganesh
2 min readFeb 3, 2021

Data replication is a necessity when data is very critical. Also, when there is a need to query data a lot of times, it is good to have separate replicated data storage to avoid any performance impact where there is a lot of write operations.

In this article, we will look into replicating CouchDB data. Data replication has a lot of challenges if implemented manually. So, when selecting a database for your application, replication feature is available or not is also an important criterion. CouchDB has the replication feature out of the box.

There are 2 easy ways to implement CouchDB data replication.

i. CouchDB Fauxton Interface

ii. POST Request endpoint _replicator

1. CouchDB Fauxton Interface

There is an option to configure replication job in CouchDB Fauxton Interface(which can be accessed <IP ADDRESS>:<PORT>/_utils endpoint), which needs Source and Target details as shown below.

Job Detail
1. Replication Job Configuration
Replication Job
Running Replication Job

2. POST Request endpoint _replicator

The request body needs source, target, etc. information as shown below.

URI: http://username:password@<IP ADDRESS 1>:<PORT>/_replicator

or

http://<IP ADDRESS 1>:<PORT>/_replicator with Auth headers

{
"_id": "replication_job_1",
"source": "http://username:password@<IP ADDRESS 1>:<PORT>/<database name>",
"target": "http://username:password@<IP ADDRESS 2>:<PORT>/<database name>",
"create_target": true,
"continuous": true
}

Here,

_id: user-defined identifier

source: Source database URL(Local/Remote)

target: Destination database URL(Local/Remote)

create_target: If this flag is set to true, then it creates the database in the target CouchDB

continuous: If this flag is set to true, there will be continuous sync of data between source and target, or else it will be a one-time data transfer.

Usually, credentials should not be exposed. In that case, the request body of the replication job contains auth headers info as follows.

{ "_id": "replication_job_2", 
"source": {
"url": "http://username:password@<IP ADDRESS 1>:<PORT>/<database name>",
"headers": { "Authorization": "Basic Y291Y2hkYjpjb3VjaGRi"
}
},
"target": {
"url": "http://username:password@<IP ADDRESS 2>:<PORT>/<database name>",
"headers": { "Authorization": "Basic Y291Y2hkYjpjb3VjaGRi"
}
},
"create_target": true,
"continuous": true
}

Here Basic Authentication mechanism is used.

There you go, try data replication in CouchDB which needs very minimal configurations/detail as shown. That's it for this Post.

Thank you…

--

--

Shivaganesh

Blockchain Developer experienced in developing Supply chain, Pharma, Telecom domain solutions using Hyperledger Fabric, R3 Corda, Symbiont Assembly and DAML