Busy Developer's Guide to CouchDB

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

Objectives

Relax! It's CouchDB

'NoSQL'

What the heck is a 'NoSQL', anyway?

"NoSQL"

"NoSQL" isn't really a great categorization

Conceptuals

Each node in a system should be able to make decisions purely based on local state. If you need to do something under high load with failures occurring and you need to reach agreement, you've lost. --Werner Vogels, CTO, Amazon

Conceptuals

The problem is one of load/scale and contention

Conceptuals

With the advent of the Web, we changed our enterprise apps

Conceptuals

Scale and load began to take down the existing infrastructure

Theory

In theory, there's no difference|between theory and practice|In practice, however.... --(various)

Conceptuals

CAP Theorem

Conceptuals

Data "shapes"

Conceptuals

Data "shapes" (continued)

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?