Couch db and_the_web
Click here to load reader
-
Upload
knuthellan -
Category
Documents
-
view
643 -
download
11
description
Transcript of Couch db and_the_web
CouchDB and the web
Knut O. Hellan
twitter.com/knuthellanknuthellan.com
NoSQL
NoSQL
Freedom of choice
Right tool for the job
Use relational databases when appropriate
Flavor of the week
Lightweight key-value:
Graph:
Document stores:
Server spanning: More
CouchDB Overview
Pros and cons
RESTful JSON API
Schema free
Incremental map reduce views
Incremental bi-directional replication
Pros and cons
Robust append-only
File backup with cp and tar
Scalable?
CouchDB views
Our database
Our database
{"_id": "123bc00725fc9f831209440793001bb6","_rev": "3-f30fca1f7fb4f387207e4756795aac74","author": "jchris","tweet": "This weekend just happened to be a good time for me to hack. Node.js CouchDB and Twitter, makes me feel like I'm part of #nodeko but I'm not","type": "tweet"}
View Design
Default mapper
function(doc) { emit(null, doc);}
Indexer
function(doc) { if (!doc.tweet) return;
var clean_text = doc.tweet.replace(/\W/g, ' ').replace(/ /g, ' '); var lower_text = clean_text.toLowerCase(); var text_vector = lower_text.split(/ /); for (var i in text_vector) { var word = text_vector[i]; if (word.length > 2) emit(word, doc._id); }}
The mapper output
http://localhost:5984/news/_design/parser/_view/index{"total_rows":50,"offset":0,"rows":[{"id":"123bc00725fc9f83120944079300093e","key":"9xmyxw","value":1},{"id":"123bc00725fc9f831209440793000f46","key":"a6exod","value":1},{"id":"123bc00725fc9f831209440793000f46","key":"and","value":1},{"id":"123bc00725fc9f831209440793001bb6","key":"and","value":1},{"id":"123bc00725fc9f83120944079300093e","key":"are","value":1},
http://localhost:5984/news/_design/parser/_view/index?key=%22couchdb%22{"total_rows":50,"offset":11,"rows":[{"id":"123bc00725fc9f83120944079300093e","key":"couchdb","value":1},{"id":"123bc00725fc9f831209440793000f46","key":"couchdb","value":1},{"id":"123bc00725fc9f831209440793001bb6","key":"couchdb","value":1}]}
Add reducer
function(keys, values, rereduce) { return sum(values);} http://localhost:5984/news/_design/parser/_view/index{"rows":[{"key":null,"value":50}]} http://localhost:5984/news/_design/parser/_view/index?key=%22couchdb%22{"rows":[{"key":null,"value":3}]}
Grouping
http://localhost:5984/news/_design/parser/_view/index?group_level=1{"rows":[{"key":"9xmyxw","value":1},{"key":"a6exod","value":1},{"key":"and","value":2},{"key":"are","value":1},
CouchDB replication
Futon Replication
Replication Modes
- Copy or replicate once - Continuous replication- Filtered replication
Multi-Couch
Offline replication
- Mobile phone
- Notebook or tablet and the cloud
Conflicts
Multi-master => possible conflicts
All masters will agree
Conflict information kept in revision history
Filtered Replication
function(doc, req) {if (doc.type && doc.type == "foo") {return true;} else {return false;}}
Filtered Replication{"_id":"myddoc","filters": {"myfilter": "function goes here"}}
Filtered Replication{ "source":"http://example.org/example-database", "target":"http://admin:[email protected]:5984/example-database", "filter":"myddoc/myfilter"}
CouchDB scaling
Alternatives
- CouchDB lounge - - Pillow
Pillow
- Reuses CouchDB functionality - Transparent for users - Automatic resharding
Pillow
Pillow
Pillow
Pillow
Pillow
CouchDB lessons learned
CouchDB Experience
Map Reduce based views are powerful
View experimentation in Futon
Three-way multi-master replication
Replication monitor
CouchDB Experience
EC2
External middleware still useful
Duck typing matches CouchDB's JSON
Now what?
Install and play with CouchDB
Visit couchdb.apache.org
Visit knuthellan.com
relax