CouchDB: A Document Database Built Around Replication

CouchDB: A Document Database Built Around Replication

CouchDB is a document database whose reason to exist is sync, not storage.

Replication is the feature

Most databases treat replication as an availability mechanism. CouchDB treats it as the primary use case: any database can replicate to any other, bidirectionally, incrementally, over plain HTTP, including between a server and a browser.

That is what PouchDB in a web page or CouchDB on a phone gives you: an application that works offline, writes locally, and converges when the network returns.

If that is your problem, nothing else in this collection solves it as directly. If it is not, CouchDB is an unusual choice.

Conflicts are explicit

Multi-master means genuine conflicts, and CouchDB does not hide them. A document can have conflicting revisions, and your application decides which wins.

That honesty is better than silent last-write-wins, and it is work you must actually do. An application that ignores conflicts will quietly lose edits.

The HTTP API

Everything is HTTP and JSON, which makes it unusually pleasant to explore.

curl http://localhost:5984/
curl -X PUT http://admin:pass@localhost:5984/mydb
curl -X POST http://admin:pass@localhost:5984/mydb -H 'Content-Type: application/json' -d '{"title":"hello"}'

Views are JavaScript map-reduce functions stored in design documents, with Mango providing a more familiar declarative query syntax.

Where it shows up

Obsidian LiveSync uses CouchDB as its backend, which is the most common reason self-hosters encounter it. Several note and field-data applications do the same.

For general document storage, MongoDB is faster and PostgreSQL with JSONB is usually the better answer entirely.

Operational caution

Never run it in admin party mode, the unauthenticated default of older versions. Set an admin password on first start.

Compaction is not automatic in all configurations: CouchDB keeps old revisions until compacted, and a database that is written to constantly grows until you run it. Our disk usage guide covers noticing before the disk fills.

CORS must be configured deliberately if a browser will talk to it directly, which is the common PouchDB arrangement.

License

CouchDB is released under the Apache License 2.0.