Database / CouchDB Interview Questions
What is the difference between one-shot and continuous replication in CouchDB?
CouchDB supports two replication modes: one-shot (the default) and continuous. The mode is set by the continuous boolean in the replication document.
One-shot replication syncs all documents changed since the last checkpoint, then completes. The replication job disappears once finished. It is appropriate for scheduled batch syncs, point-in-time backups, or bootstrapping a new replica.
Continuous replication runs indefinitely after initial sync. It keeps a long-lived _changes feed connection open to the source, processing new changes as they arrive in near real-time. The replication job persists in the _replicator database and is restarted automatically after node restarts.
# One-shot replication via _replicator database
curl -X POST http://admin:pass@localhost:5984/_replicator \
-H "Content-Type: application/json" \
-d '{
"_id": "one-time-backup",
"source": "http://localhost:5984/mydb",
"target": "http://replica:5984/mydb",
"continuous": false,
"create_target": true
}'
# Continuous replication
curl -X POST http://admin:pass@localhost:5984/_replicator \
-H "Content-Type: application/json" \
-d '{
"_id": "live-sync-to-replica",
"source": "http://localhost:5984/orders",
"target": "http://replica:5984/orders",
"continuous": true
}'
# Check replication status
curl http://admin:pass@localhost:5984/_scheduler/jobs
Continuous replication introduces a persistent connection that consumes resources on both nodes. For high-volume databases, monitor the scheduler via /_scheduler/jobs and /_scheduler/docs to detect stalled or crashing replication jobs. A job that enters a crash-loop loop usually indicates a network issue, authentication problem, or an unfixable conflict on the target.
More Related questions...