CouchDB is a document-oriented database, a non-relational datastore, one which belongs to the group of NoSQL databases. (More on NoSQL here.) Contrary to a relational database (RDBMS) in which data is contained in tables, rows, and columns, CouchDB contains a collection of JSON documents in a modified B-Tree file structure, each of which is indexed by a single unique key. (The key is often a GUUID, but it need not be.) CouchDB documents can have any number of files attached to them, including their MIME type, and each of these documents contains a revision number which CouchDB uses to support multiversion concurrency control (MVCC). CouchDB is accessed via HTTP only; there are no application-specific binary protocols used, making it an ideal system to be put behind load-balancers and proxies. As such, one of the tools of the trade with which to quickly access CouchDB is curl. For example, in order to create a database in CouchDB and add the document shown above, I do the following:
The first curl invocation creates a database called
demo, and the
second creates a new document with a key
1 reading the content of the data
from the specified JSON text. CouchDB responds with a JSON structure
indicating errors or success. CouchDB’s Futon utility, also accessible from a
Web browser, shows the result and lets me modify the document, attach a file,
etc. (CouchDB’s tagline, relax, is neatly carried on in the name
futon.) According to its author, CouchDB is largely
inspired by the Lotus Notes back-end (i.e. Lotus Domino), and I see
a number of parallels:
- CouchDB detects and flags document conflicts when a document is updated on more than one server. However, contrary to Notes, it cannot merge individual portions of a document – that is an exercise left to the application.
- CouchDB and Lotus Notes are predestined for offline use with subsequent replication when online.
- I can set up CouchDB on a number of nodes (systems) and have a single master replicate to any number of slave nodes (on demand or continuously), and I can have an application write to any number of those nodes, effectively creating a multi-master system, just as with Lotus Notes. (The Lotus Notes client’s automatic failover to a different cluster node I would implement with a proxy, just as I’d have to do with a Notes Web application.) As with Lotus Domino, a cluster of CouchDB nodes need not be implemented on identical hardware or operating system – a great plus.
- CouchDB integrates a view model for aggregating and reporting on documents in a database. Views are built dynamically, and they are defined withing special design documents. This is quite similar to they way I view Notes views.
There are, however, a number of things that Lotus Notes includes out of the box, which CouchDB doesn’t:
- Notes has a very high and very granular level of security. (Encrypted connections, encrypted databases, reader and author fields, etc.)
- Due to its “all-in-a-box” model, Lotus Notes integrates e-mail, calendaring and directory services, which CouchDB doesn’t do, of course, as it is a database layer only.