Configure Continuous Replication Between Two CouchDB Instances
Step‑by‑step guide to create a persistent replication job that keeps a source and target CouchDB database in sync, with verification and recovery tips.
01 Nov 2025, 07:06 UTC

Desired Outcome
Establish a continuous replication link from a source CouchDB database to a target CouchDB database so that any create, update, or delete operation on the source is automatically propagated to the target, and the replication survives node restarts.
Prerequisites
- Two CouchDB instances (version 3.x recommended) running and accessible via HTTP/HTTPS.
- Network connectivity between the instances (firewall rules allow traffic on the CouchDB port, default 5984).
- A user account with the
_replicatorrole and read/write access to both the source and target databases (e.g.,replicatoruser). - Both instances should have the same major version to avoid protocol mismatches.
Procedure
1. Create the replication document
Replication jobs are stored as documents in the _replicator database. You can create the document on any node; here we use the source node for clarity.
# Replace placeholders with your actual values curl -X PUT http://replicator:password@source-host:5984/_replicator/my-replication \ -H "Content-Type: application/json" \ -d '{ "_id": "my-replication", "source": "http://replicator:password@source-host:5984/source-db", "target": "http://replicator:password@target-host:5984/target-db", "continuous": true, "create_target": true }'Explanation of fields:
_id– unique identifier for the replication job.source– URL of the source database (include credentials if authentication is required).target– URL of the target database.continuous– set totrueto keep the job running after the initial sync.create_target– optional; creates the target database if it does not exist.
2. Verify the job is started
After posting the document, CouchDB launches a replication process. Check the active tasks list:
curl -s http://replicator:password@source-host:5984/_active_tasks | jq '.[] | select(.type=="replication")'You should see an entry with
"status":"running"(or"triggered"briefly before it becomes running). The replication document itself will have a field_replication_statethat transitions from"triggered"to"running".3. Confirm data synchronization
Insert a test document into the source database and verify it appears on the target.
# Add a test doc to source curl -X POST http://replicator:password@source-host:5984/source-db \ -H "Content-Type: application/json" \ -d '{"test":"value","timestamp":"'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"}'Wait a few seconds (latency depends on network and load) then query the target:
curl -s http://replicator:password@target-host:5984/target-db/_all_docs?include_docs=true | jq '.rows[] | select(.doc.test=="value")'If the document appears, replication is working. Repeat with an update or delete to confirm those operations propagate as well.
4. Monitor for errors
Replication errors are stored in the replication document’s
_last_errorfield. Periodically check:curl -s http://replicator:password@source-host:5984/_replicator/my-replication | jq '._last_error'An empty value or
nullindicates no recent errors. Also watch the_replication_idfield; a steadily increasing value shows ongoing activity.Expected Checks
- Replication document exists in
_replicatorwith correctsourceandtargetURLs._active_tasksshows a replication task with statusrunning(orcompletedfor one‑shot).- The replication document’s
_replication_stateisrunning(continuous) and_last_erroris empty.- Test create/update/delete operations on the source are visible on the target within expected latency.
Recovery Options
If replication stops:
- Check connectivity: verify that both hosts can reach each other on the CouchDB port (e.g.,
telnet target-host 5984). - Inspect credentials: ensure the replicator user still exists and has the required roles.
- Review logs: CouchDB logs (
/opt/couchdb/log/couch.logby default) contain replication‑specific messages. - Restart the job: you can delete and recreate the replication document, or simply set
continuoustofalsethen back totrueto trigger a restart. - Handle conflicts: if the same document was updated on both sides, CouchDB stores conflicting revisions. Use the
_conflictsendpoint to examine them and apply application‑level resolution.
Limitations
Continuous replication generates persistent network traffic; monitor bandwidth usage, especially in high‑write environments. Document conflicts are not resolved automatically—your application must decide which revision wins. Replication does not transfer design documents or security objects unless they are included as regular documents in the source database.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.