Chapter 3. CouchDB

CouchDB started as a document store with the great ability to replicate data between nodes. This makes it ideal for use cases that involve eventual or relaxed consistency. The built-in replication also makes it the ideal platform for synchronization between mobile, desktop and server. CouchDB sports no fixed schema. Instead it stores documents which are formatted in JSON. JSON, being a lightweight and easy-to-understand notation for simple data structures, is great for this task. And without a rigid schema, CouchDB excels at being a fast developer-friendly datastore.

How Does CouchDB Work?

CouchDB is eventually consistent. CAP Theorem states that any database can only have two out of three of the core properties of a data store. These are:

  • Consistency: That all database clients see the same copy of the data.

  • Availability: that all database clients are able to access a version of the data.

  • Partition tolerance: That the database can be split over multiple servers.

Since CouchDB’s focus is on being partition-tolerant and highly available, this means it is eventually consistent.

Replication

CouchDB’s built in replication can be super useful in creating a highly available and partition tolerant system. Locally, CouchDB uses MVCC ( Multi-Version Concurrency Control) to provide consistent access to data. This means that versions of documents are stored, and updates are appended. Read requests can always read from the most recent version of the document with no need for locking ...

Get Getting Started with GEO, CouchDB, and Node.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.