vidoop couchdb talk

38

Upload: chris-anderson

Post on 17-Dec-2014

2.738 views

Category:

Technology


0 download

DESCRIPTION

Overview of CouchDB,Demo of CouchApp,Future of Distributed Identity

TRANSCRIPT

Page 1: Vidoop CouchDB Talk
Page 2: Vidoop CouchDB Talk

Who Am I?• Chris Anderson <[email protected]>

• CouchDB committer

• Blog: http://jchrisa.net

Page 3: Vidoop CouchDB Talk

Couch History

• Damien Katz <http://damienkatz.net/>

• Worked on Lotus Notes & MySQL

• Started CouchDB in 2005

• 2006: Moved to Erlang, JSON and JavaScript

• Approaching 0.9 Release

Page 4: Vidoop CouchDB Talk

2008 Erlang User of the Year

Page 5: Vidoop CouchDB Talk

This Talk

• Hello CouchDB

• Hands on with CouchApp

• The Future

• Get Involved

Page 6: Vidoop CouchDB Talk

Hello CouchDB• JSON Documents

• HTTP / REST (You already know the API)

• ACID Storage Engine

• Map Reduce Views

• Replication for Freedom

• Portable Standalone Applications

Page 7: Vidoop CouchDB Talk

JSON Documents

{“json” : “key / value pairs”,“_id” : “some uuid”,“_rev” : “mvcc key”,

“string keys” : [1,2,3,”four”,null],“schema free” : true}

Your programming language supports JSON.

Page 8: Vidoop CouchDB Talk

JSON Documents

{“json” : “key / value pairs”,“_id” : “some uuid”,“_rev” : “mvcc key”,

“string keys” : [1,2,3,”four”,null],“schema free” : “flexible”}

Adapt data as your application changes.

Page 9: Vidoop CouchDB Talk

HTTP / CRUD

GET read

PUT create or update

DELETE delete

POST bulk operation

You already know the API.

Page 10: Vidoop CouchDB Talk

ACID Storage Engine

• Append Only

• Multi Version Concurrency Control

• B-Tree Indexes O(log n)

• Attachment Streaming

Oooh, self-similar

Page 11: Vidoop CouchDB Talk

Map Reduce ViewsDocs Map

{ “user” : “Chris”,“points” : 3 }

{ “user” : “Joe”,“points” : 10 }

{ “user” : “Alice”,“points” : 5 }

{ “user” : “Mary”,“points” : 9 }

{ “user” : “Bob”,“points” : 7 }

function(doc) {if (doc.user && doc.points) {

emit(doc.user, doc.points);}

}

{ “key” : “Alice”, “value” : 5 }{ “key” : “Bob”, “value” : 7 }

{ “key” : “Chris”, “value” : 3 }{ “key” : “Joe”, “value” : 10 }{ “key” : “Mary”, “value” : 9 }

Reduce

Alice ... Chris: 15Everyone: 34

function(keys, values, rereduce) { return sum(values);}

Page 12: Vidoop CouchDB Talk

Peer-Based Replication for Freedom

TriggeredIncremental

Filtered*

Page 13: Vidoop CouchDB Talk
Page 14: Vidoop CouchDB Talk
Page 15: Vidoop CouchDB Talk
Page 16: Vidoop CouchDB Talk
Page 17: Vidoop CouchDB Talk
Page 18: Vidoop CouchDB Talk
Page 19: Vidoop CouchDB Talk
Page 20: Vidoop CouchDB Talk
Page 21: Vidoop CouchDB Talk

Let’s Replicate Everything!

• Take full advantage of CouchDB

• View-source Open Source

• The Future is Distributed

Page 22: Vidoop CouchDB Talk

But that’s not RESTful!Representational State Transfer...

it’s more than just verbs,it’s the hyperlinks.

Webpage

Webpage

Webpage

Webpage

∴We need HTML.

Page 23: Vidoop CouchDB Talk

Render JSON Docs as HTMLshows/post.js /drl/_show/sofa/post/Hello-World-For-Real-This-Time

Page 24: Vidoop CouchDB Talk

Render Views as HTMLlists/index.js /drl/_list/sofa/index/recent-posts?descending=true&limit=8

Page 25: Vidoop CouchDB Talk

Hands On with CouchApp

• CouchApp is just some filesystem helpers

• Embodies “best practices”

• CouchApp is not opinionated, CouchDB is.

• Don’t shoot the messenger.

Page 26: Vidoop CouchDB Talk

Install CouchApp

sudo easy_install couchapp

or

git clone git://github.com/jchris/couchapp.git

Page 28: Vidoop CouchDB Talk

Setup Credentials

edit: /usr/local/etc/couchdb/local.ini

add:[admins]

username = secretpassword

Leaky Abstraction!

Page 29: Vidoop CouchDB Talk

Get the Example App(ajax version)

couchapp clone http://jchrisa.net/sofa-ajax/_design/sofa

cd sofa

couchapp pushhttp://user:pass@localhost:5984/sofa-ajax

Page 30: Vidoop CouchDB Talk

The Guts

Page 31: Vidoop CouchDB Talk

First Post!

Page 32: Vidoop CouchDB Talk

Firebug to see requests

Page 33: Vidoop CouchDB Talk

Upgrade to real HTML

couchapp clone http://jchrisa.net/drl/_design/sofa

cd sofa

couchapp pushhttp://user:pass@localhost:5984/sofa

Page 34: Vidoop CouchDB Talk

How’s it Work?

Macros so functions can be in multiple files.

Page 35: Vidoop CouchDB Talk

Templating

Page 36: Vidoop CouchDB Talk

The Future

• Key-Centric Identity?

• P2P Topologies don’t leave room to trust the server.

• Multi-Node clusters

• High performance, large databases

Page 37: Vidoop CouchDB Talk

Resources

• #couchdb and #couchapp on irc.freenode.net

• http://couchdb.apache.org for mailing lists

• http://planet.couchdb.org/

• http://books.couchdb.org/relax/

• Twitter search for “couchdb”

Page 38: Vidoop CouchDB Talk

Thank You!