CouchDB Apache
Seen REST talk by @ramsey? Seen DB talk by @scottmac? Hi! Jan Lehnardt / @janl / CouchDB Committer *bragging* jan@php.net since October 2001 jan@apache.org since February 2008 <commercial> Director at couch.io </commercial>
Relax! http://www.flickr.com/photos/freelancing_god/3271488152/
Agenda Learn how to use CouchDB replication for load-balancing, fault tolerance, offline work and backup. We are showing how to set up each and what you need to look out for.
Agenda Finally, this talk is sprinkled with neat tricks and best practices for deploying CouchDB. Which load balancers are people using, how to make the best use of caching, etc.
Agenda Basics Replication Mind shifting
http://www.flickr.com/photos/stilleben2001/223243329/ Documents
Documents Self contained Schema is optional Feel natural
Schema Free (JSON) { "_id": "BCCD12CBB", "_rev": "1-AB764C", "type": "person", "name": "Darth Vader", "age": 63, "headware": ["Helmet", "Sombrero"], "dark_side": true }
Schema Free (JSON) { "_id": "BCCD12CBB", "_rev": "2-AB764C", "type": "person", "name": "Darth Vader", "age": 63, "headware": ["Helmet", "Sombrero"], "dark_side": true }
Schema Free (JSON) { "_id": "BCCD12CBB", "_rev": "3-AB764C", "type": "person", "name": "Darth Vader", "age": 63, "headware": ["Helmet", "Sombrero"], "dark_side": true } Access Tokens for MVCC, no locking
Access Tokens for MVCC attachments Schema Free (JSON) { "_id": "BCCD12CBB", "_rev": "3-AB764C", "type": "person", "name": "Darth Vader", "age": 63, "headware": ["Helmet", "Sombrero"], "dark_side": true }
RESTful HTTP API CRUD Create HTTP PUT /db/mydocid Read HTTP GET /db/mydocid Update HTTP PUT /db/mydocid Delete HTTP DELETE /db/mydocid
HTTP Infrastructure Your browser curl / wget ext/curl, Net_HTTP, Zend_Http_Client PHPIllow (by Kore Nordmann) Apache mod_proxy (couch.io) Varnish (BBC demo) nginx ( + custom consistent hashing plugin, meebo.com) Custom (Tomcat, BBC)
Replication
periodic, notifier system
Amsterdam San Francisco
P2P apps
Conflicts
Conflict resolution by example A B
Conflict resolution by example A B
Conflict resolution by example A B
Conflict resolution by example A B
Conflict resolution by example A B
Conflict resolution by example A B
Conflict resolution by example A B
Conflict resolution by example A B
Conflict resolution by example A B
Conflict resolution by example A B
Conflict resolution by example A B
Mind Shifting
Where is my auto_increment?
http://www.flickr.com/photos/andresrueda/3259487071
?
http://www.flickr.com/photos/fbar/178379231/
MOAR RANDOM 128 random bits!
UUIDs for identification Natural keys for sorting
dropbox Accept Conflicts
Referential Integrity, JOINs and related data
Referential Integrity When in doubt, look at The Web*: Links can point to 404 (*Yeah, REST) @ramsey talk
JOINs Use the power of Views to create an index that sorts related rows next to each other.
JOINs function(doc) { if(doc.type == "post") { emit([doc._id, doc.date], doc); } else if(doc.type == "comment" { emit([doc.post_id, doc.date], doc); }
JOINs function(doc) { if(doc.type == "post") { emit([doc._id, doc.date], doc); } else if(doc.type == "comment" { emit([doc.post_id, doc.date], doc); }
JOINs emit([doc._id, doc.date], doc); key value ["53421", "2009-05-23"] {"type":"post" } ["53421", "2009-05-24"] {"type":"comment" } ["53421", "2009-05-25"] {"type":"comment" }
GET /db/_design/dname/_view/vname? startkey=["53421", null]& endkey=["53421", {}]
Evaluating CouchDB
make your own cloud resilient storage Evaluating K/V-Stores Technical suitability Healthy (open source) project Failure behaviour Operational complexity Commercial support Speed / Concurrency
9k docs, 4 writers, 16 readers CouchDB: 2400 reads/s, 800 writes/s BBC CouchDB reads CouchDB writes MDB reads MDB writes
http://www.flickr.com/photos/andrewdotcameron/89161276
Web: http://couchdb.apache.org/ Twitter: @CouchDB IRC: #couchdb on Freenode Hosting: http://couch.io/ (invite only) Support: http://couchio.com/ I can haz feedback? http://joind.in/584 *hugs*
erlang Questions?
ank You!