Busy Developer's Guide to CouchDB

ted.neward@newardassociates.com | Blog: http://blogs.newardassociates.com | Github: tedneward | LinkedIn: tedneward

Objectives

Relax! It's CouchDB

History of Databases

Those who cannot remember the past....

History of Databases

We didn't always have databases

History of Databases

Indexed Sequential Access Method (ISAM) files

History of Databases

Problems with ISAM

History of Databases

Transactional processing

History of Databases

Interactive computing

History of Databases

E.F. (Ted) Codd

History of Databases

Codd's model slowly ate the world

History of Databases

Other models

History of Databases

CAP Theorem

What was wrong with the RDBMS, anyway?

CAP Theorem

Pre-Web

CAP Theorem

Pre-Web

CAP Theorem

The Web

CAP Theorem

Load/scale and contention

CAP Theorem

The Result: Bad

CAP Theorem

The Solution (sort of)

CAP Theorem

Practical

CAP Theorem

CAP begat PACELC

Data Models: Document-Oriented Data

What does that mean?

Data Models: Document-Oriented Data

What is a Document-Oriented Data Model?

Data Models: Document-Oriented Data

What is a document?

Data Models: Document-Oriented Data

Advantages

Data Models: Document-Oriented Data

Disadvantages

Data Models: Document-Oriented Data

Canonical Doc-Oriented examples

CouchDB

Document-oriented REST

CouchDB

CouchDB: document-oriented

CouchDB

CouchDB: document-oriented

Basics

No locks; MVCC instead

Basics

CouchDB's principal I/O is HTTP/REST

Basics

CouchDB's principal data is the document

Basics

Assume this is stored in person.json

{
   "_id": "286ccf0edf77bfb6e780be88ae000d0b",
   "firstname": "Ted",
   "lastname": "Neward",
   "age": 40
}

... then insert it into Couch like so:

curl -X PUT http://localhost:5984/%1 -d @%2 -H "Content-Type: application/json"

Basics

Documents can have attachments

Basics

Documents can be inserted in bulk

Basics

Retrieving an individual document is just a GET

Basics

Retrieving multiple documents uses Views

API

Views can be constrained by query params

Basics

Updating a individual document is just a POST

CouchDB and 'Code'

What about executable bits in/with Couch?

Code

Recall: Everything is a document * a document can contain JavaScript code, executed by CouchDB * this is called a 'design document' * a design document is a doc URL-prefixed with "_design"

{
    "_id" : "_design/example",
    "views" : {
        "all_docs" : {
            "map" : "function(doc) { emit(doc._id, doc._rev) }"
        }
    }
}

Code

CouchDB supports server-side validation

Code

CouchDB can also show arbitrary pages

CouchApps

CouchDB is a single-tier app server

CouchApps

CouchApp is a framework/build system for building CouchDB applications (design docs)

Summary

CouchDB is... different

CouchDB Resources

Where to go from here

References

References

Credentials

Who is this guy?