SlideShare a Scribd company logo
1 of 82
*




    CouchDB
No SQL? No Driver?
   No problem.
      Angel Pizarro
    angel@upenn.edu


                      * www.bauwel-movement.co.uk/ sculpture.php
About Me
Me: CBIL alumni! Work in mass spec
proteomics
Lots of data in lots of formats in
bioinformatics
Ruby for programming and Ruby on Rails for
Web apps
 But that doesn’t matter for CouchDB!
Interested in CouchDB for AWS deployment
Overview
Talk about Key-Value stores
Introduce some general theory and
concepts
CouchDB specifics
Example problem
More CouchDB specifics
Questions?
Key-Value Databases
Datastore of values indexed
by keys (duh!)
Hash or B-Tree index for
keys
                                  Cassandra
  Hash is FAST, but only allows
  single-value lookups
  B-Tree is slower, but allows
  range queries
Horizontally scalable - via key
partitioning
The CAP theory : applies when business
     logic is separate from storage

Consistency vs. Availability
vs. Partition tolerance
RDBMS = enforced
consistency
PAXOS = quorum
consistency
CouchDB (and others) =
eventual consistency
and horizontally
scalable


  http://www.julianbrowne.com/article/viewer/brewers-cap-theorem
CouchDB
CouchDB
Document Oriented Database
 JSON documents
CouchDB
Document Oriented Database
 JSON documents
HTTP protocol using REST operations
 No direct native language drivers *
 Javascript is the lingua franca




                       * Hovercraft: http://github.com/jchris/hovercraft/
CouchDB
Document Oriented Database
 JSON documents
HTTP protocol using REST operations
 No direct native language drivers *
 Javascript is the lingua franca
ACID & MVCC guarantees on a per-
document basis



                       * Hovercraft: http://github.com/jchris/hovercraft/
CouchDB
Document Oriented Database
 JSON documents
HTTP protocol using REST operations
 No direct native language drivers *
 Javascript is the lingua franca
ACID & MVCC guarantees on a per-
document basis
Map-Reduce indexing and views


                       * Hovercraft: http://github.com/jchris/hovercraft/
CouchDB
Document Oriented Database
 JSON documents
HTTP protocol using REST operations
 No direct native language drivers *
 Javascript is the lingua franca
ACID & MVCC guarantees on a per-
document basis
Map-Reduce indexing and views
Back-ups and replication are easy-peasy
                       * Hovercraft: http://github.com/jchris/hovercraft/
Javascript Object
    Notation
Javascript Object
    Notation            *




               * http://www.json.org
Example JSON

{
    “name”: “J. Doe”,
    “friends”: 0,
      “traits”: [“nice”, “outgoing”]
}
REST
REST
Representational State Transfer
REST
Representational State Transfer
Clients-Server separation with uniform interface
(HTTP)
REST
Representational State Transfer
Clients-Server separation with uniform interface
(HTTP)
  Load-balancing, caching, authorization & authentication,
  proxies
REST
Representational State Transfer
Clients-Server separation with uniform interface
(HTTP)
  Load-balancing, caching, authorization & authentication,
  proxies
Stateless - client is responsible for creating a self-
sufficient request
REST
Representational State Transfer
Clients-Server separation with uniform interface
(HTTP)
  Load-balancing, caching, authorization & authentication,
  proxies
Stateless - client is responsible for creating a self-
sufficient request
Resources are cacheable - servers must mark
non-cacheable resources as such
REST
Representational State Transfer
Clients-Server separation with uniform interface
(HTTP)
  Load-balancing, caching, authorization & authentication,
  proxies
Stateless - client is responsible for creating a self-
sufficient request
Resources are cacheable - servers must mark
non-cacheable resources as such
Only 5 HTTP verbs
REST
Representational State Transfer
Clients-Server separation with uniform interface
(HTTP)
  Load-balancing, caching, authorization & authentication,
  proxies
Stateless - client is responsible for creating a self-
sufficient request
Resources are cacheable - servers must mark
non-cacheable resources as such
Only 5 HTTP verbs
 GET, PUT, POST, DELETE, HEAD
CouchDB
 REST/CRUD
 GET          read


 PUT     create or update


DELETE   delete something


POST     bulk operations
CouchDB passes the
    ACID test
Each document is completely self-sufficient
Each document has a version number
An update operation writes a complete
new copy of the the record and is assigned
the new version number
Append-only file structure allows the write
to occur while still serving read requests
MVCC                    RDBMS   CouchDB
Multi-Version
Concurrency Control
RDBMS enforces consistency
using read/write locks
Instead of locks, CouchDB
just serve up old data
Multi-document (mutli-row)
transactional semantics
must be handled by the
application
Database API
Create a DB:

$ curl -X PUT http://127.0.0.1:5984/friendbook
{"ok":true}
Database API
Create a DB:
       Protocol

$ curl -X PUT http://127.0.0.1:5984/friendbook
{"ok":true}
Database API
Create a DB:
                   CouchDB server

$ curl -X PUT http://127.0.0.1:5984/friendbook
{"ok":true}
Database API
Create a DB:
                                        DB name

$ curl -X PUT http://127.0.0.1:5984/friendbook
{"ok":true}
Database API
Create a DB:

$ curl -X PUT http://127.0.0.1:5984/friendbook
{"ok":true}

Try it Again: {"error":"db_exists"}
Database API
Create a DB:

$ curl -X PUT http://127.0.0.1:5984/friendbook
{"ok":true}

Try it Again: {"error":"db_exists"}
                                      Not recoverable!
Delete a DB:
 $ curl -X DELETE http://localhost:5984/friendbook
 {"ok":true}
Inserting a document
All insert require that you give a unique ID. You can
request one from CouchDB:
$ curl -X GET http://localhost:5984/_uuids
{"uuids":["d1dde0996a4db7c1ebc78fb89c01b9e6"]}
Inserting a document
  All insert require that you give a unique ID. You can
  request one from CouchDB:
  $ curl -X GET http://localhost:5984/_uuids
  {"uuids":["d1dde0996a4db7c1ebc78fb89c01b9e6"]}


We’ll just give one:
$ curl -X PUT http://localhost:5984/friendbook/j_doe 
   -d @j_doe.json

{"ok":true,
"id":"j_doe",
"rev":"1-062af1c4ac73287b7e07396c86243432"}
Inserting a document
  All insert require that you give a unique ID. You can
  request one from CouchDB:
  $ curl -X GET http://localhost:5984/_uuids
  {"uuids":["d1dde0996a4db7c1ebc78fb89c01b9e6"]}


We’ll just give one:
$ curl -X PUT http://localhost:5984/friendbook/j_doe 
   -d @j_doe.json
                                  Read a JSON file
{"ok":true,
"id":"j_doe",
"rev":"1-062af1c4ac73287b7e07396c86243432"}
Full JSON document
Before
{ "name": "J. Doe",
 "friends": 0 }


After
{   "_id":       "j_doe",
    "_rev":      "1-062af1c4ac73287b7e07396c86243432",
    "name":      "J. Doe",
    "friends":   0 }
Updating a document
$ curl -X PUT http://localhost:5984/friendbook/j_doe 
      -d '{"name": "J. Doe", "friends": 1 }'
{"error":"conflict","reason":"Document update conflict."}
Updating a document
$ curl -X PUT http://localhost:5984/friendbook/j_doe 
      -d '{"name": "J. Doe", "friends": 1 }'
{"error":"conflict","reason":"Document update conflict."}

        Must give _rev (revision number) for updates!
                                  revised.json
           { "_rev":"1-062af1c4ac73287b7e07396c86243432",
             "name":"J. Doe", "friends": 1 }


$ curl -X PUT http://localhost:5984/friendbook/j_doe -d @revised.json

{"ok":true,"id":"j_doe","rev":"2-0629239b53a8d146a3a3c4c63e
2dbfd0"}
Deleting a document
$ curl -X DELETE http://localhost:5984/friendbook/j_doe
{"error":"conflict","reason":"Document update conflict."}

        Must give revision number for deletes!
$ curl -X DELETE http://localhost:5984/friendbook/j_doe?
rev=2-0629239b53a8d146a3a3c4c63e2dbfd0
{"ok":true,"id":"j_doe",
 "rev":"3-57673a4b7b662bb916cc374a92318c6b"}

    Returns a revision number for the delete
$ curl -X GET http://localhost:5984/friendbook/j_doe
{"error":"not_found","reason":"deleted"}
Bulk operation
            POST /database/_bulk_docs with a
            JSON document containing all of the new
            or updated documents.
// documents to bulk upload
{
  "docs": [
    {"_id": "0", "integer": 0, "string":   "0"},
    {"_id": "1", "integer": 1, "string":   "1"},
    {"_id": "2", "integer": 2, "string":   "2"}
  ]
                                           // reply from CouchDB
}
                                           [
                                              {"id":"0","rev":"1-62657917"},
                                              {"id":"1","rev":"1-2089673485"},
                                              {"id":"2","rev":"1-2063452834"}
                                           ]
GOTCHA’s!
Version storage is not guaranteed!
 Do not use this as a VCS!
 POST to /db/_compact deletes all older vesions
To “roll back a transaction” you must:
 Retrieve all related records, cache these
 Insert any updates to records.
 On failure, use the returned revision numbers to
 re-insert the older record as a new one
Our Example Problem
Our Example Problem
 Hello world? Blog? Twitter clone?
Our Example Problem
 Hello world? Blog? Twitter clone?
 Let’s store all human proteins instead
Our Example Problem
               Hello world? Blog? Twitter clone?
               Let’s store all human proteins instead

LOCUS     YP_003024029           227 aa         linear PRI 09-JUL-2009
DEFINITION cytochrome c oxidase subunit II [Homo sapiens].
ACCESSION YP_003024029
VERSION    YP_003024029.1 GI:251831110
DBLINK    Project:30353
DBSOURCE REFSEQ: accession NC_012920.1
KEYWORDS .
SOURCE     mitochondrion Homo sapiens (human)
 ORGANISM Homo sapiens
       Eukaryota; Metazoa; Chordata; Craniata; Vertebrata; Euteleostomi;
       Mammalia; Eutheria; Euarchontoglires; Primates; Haplorrhini;
       Catarrhini; Hominidae; Homo.
Our Example Problem
              Hello world? Blog? Twitter clone?
              Let’s store all human proteins instead

LOCUS     YP_003024029           227 aa         linear PRI 09-JUL-2009
DEFINITION cytochrome c oxidase subunit II [Homo sapiens].
ACCESSION YP_003024029
VERSION    YP_003024029.1 GI:251831110
DBLINK    Project:30353
                      FEATURES
DBSOURCE REFSEQ: accession NC_012920.1  Location/Qualifiers
KEYWORDS .               source       1..227
SOURCE                             /organism="Homo sapiens"
           mitochondrion Homo sapiens (human)
 ORGANISM Homo sapiens             /organelle="mitochondrion"
                                   /isolation_source="caucasian"
       Eukaryota; Metazoa; Chordata; Craniata; Vertebrata; Euteleostomi;
                                   /db_xref="taxon:9606"
       Mammalia; Eutheria; Euarchontoglires; Primates; Haplorrhini;
       Catarrhini; Hominidae; Homo./tissue_type="placenta"
                                   /country="United Kingdom: Great Britain"
                                   /note="this is the rCRS"
                         Protein      1..227
                                   /product="cytochrome c oxidase subunit II"
                                   /calculated_mol_wt=25434
                                                                         http://www.ncbi.nlm.nih.gov/
Our Example Problem
              Hello world? Blog? Twitter clone?
              Let’s store all human proteins instead

LOCUS     YP_003024029           227 aa         linear PRI 09-JUL-2009
DEFINITION cytochrome c oxidase subunit II [Homo sapiens].
ACCESSION YP_003024029
VERSION    YP_003024029.1 GI:251831110
DBLINK    Project:30353
                      FEATURES
DBSOURCE REFSEQ: accession NC_012920.1  Location/Qualifiers
KEYWORDS .               source       1..227
SOURCE                             /organism="Homo sapiens"
           mitochondrion Homo sapiens (human)
 ORGANISM Homo sapiens             /organelle="mitochondrion"
                                   /isolation_source="caucasian"
       Eukaryota; Metazoa; Chordata; Craniata; Vertebrata; Euteleostomi;
                                   /db_xref="taxon:9606"
       Mammalia; Eutheria; Euarchontoglires; Primates; Haplorrhini;
       Catarrhini; Hominidae; Homo./tissue_type="placenta"
                                   /country="United Kingdom: Great Britain"
                                   /note="this is the rCRS"
                         Protein      1..227
                                   /product="cytochrome c oxidase subunit II"
                                   /calculated_mol_wt=25434
                                                                         http://www.ncbi.nlm.nih.gov/
Futon : A Couchapp
Futon : A Couchapp
Futon : A Couchapp
Futon : A Couchapp


          This one is
          going to be
         a bit tougher
Design Documents
Design Documents
The key to using CouchDB as more than a
key-value store
Design Documents
The key to using CouchDB as more than a
key-value store
Just another JSON document, but contain
javascript functions that CouchDB treats
as application code
 Functions are executed within CouchDB
Design Documents
The key to using CouchDB as more than a
key-value store
Just another JSON document, but contain
javascript functions that CouchDB treats
as application code
 Functions are executed within CouchDB
Contain sections for map-reduce views,
data validation, alternate formatting, ...
 Also library code & data structures specific to
 the design document
Soy Map!
Soy Map!
Views use a Map-Reduce model for
indexing and defining “virtual” documents
 Fits well with assumptions of self-sufficient
 documents and eventual consistency
Soy Map!
Views use a Map-Reduce model for
indexing and defining “virtual” documents
 Fits well with assumptions of self-sufficient
 documents and eventual consistency
Map function is applied to all documents in
the database
 Emits (parts of) documents that pass mustard
 Indexing is incremental after an initial definition
 You can choose to defer an index update for
 insert speed
Map function example
Map function example
Complex Map
Complex Map
View Result
View Result
GET by the indexed key
GET by the indexed key

  GET /refseq_human/_design/gb/_view/dbXref?key="GeneID:10"

{"total_rows":7,"offset":2,"rows":[
   {"id":"NP_000006",
    "key":"GeneID:10",
    "value":"NP_000006"}
]}
Reduce functions
Optional and used in concert with a
specific map function
Great for summarizing or collating
numerical data points
 E.g. counts, number of over time X, average
 load, probability of conversion
Not really applicable to our example, so
we’ll not cover it today
Show me the ... HTML?
 JSON is great, but what about, ya know,
 something useful?
 You can make a separate app to reformat
 the JSON
 OR you can use the “shows” section of a
 _design document.
  Rich formating possible with functions,
  templates, and special include macros
FASTA format
“shows” : {
  “fasta” : “function(doc, req) {
           return ‘>’ +
                       doc._id +
                       ‘n’ +
                       doc.seq;
         }”,
...
FASTA format
“shows” : {
  “fasta” : “function(doc, req) {
           return ‘>’ +
                       doc._id +
                       ‘n’ +
                       doc.seq;
         }”,
...

     GET /refseq_human/_design/gb/_show/fasta/NP_000006
  >NP_000006
  MDIEAYFERIGYKNSRNKLDLETLTDILEHQIRAVPFENLNMHCGQAMELGLEAIFDHIVRR
  NRGGWCLQVNQLLYWALTTIGFQTTMLGGYFYIPPVNKYSTGMVHLLLQVTIDGRNYIV
  DAGSGSSSQMWQPLELISGKDQPQVPCIFCLTEERGIWYLDQIRREQYITNKEFLNSHLLPK
  KKHQKIYLFTLEPRTIEDFESMNTYLQTSPTSSFITTSFCSLQTPEGVYCLVGFILTYRKFNYKD
  NTDLVEFKTLTEEEVEEVLRNIFKISLGRNLVPKPGDGSLTI
Backups & Replication
Backups & Replication
Backup: simply copy the database file
Backups & Replication
Backup: simply copy the database file
Replicate: send a POST request with a source and
target database
Backups & Replication
Backup: simply copy the database file
Replicate: send a POST request with a source and
target database
   Source and target DB’s can either be local (just
   the db name) or remote (full URL)
Backups & Replication
Backup: simply copy the database file
Replicate: send a POST request with a source and
target database
   Source and target DB’s can either be local (just
   the db name) or remote (full URL)
   “continous”: true option will register the
   target to the source’s _changes notification API
Backups & Replication
     Backup: simply copy the database file
     Replicate: send a POST request with a source and
     target database
        Source and target DB’s can either be local (just
        the db name) or remote (full URL)
        “continous”: true option will register the
        target to the source’s _changes notification API

$ curl -X POST http://localhost:5984/_replicate 
 -d '{"source":"db", "target":"db-replica", "continuous":true}'
Data normalization? Schema?
   Foreign Keys? Column
        Constraints?
Data normalization? Schema?
   Foreign Keys? Column
        Constraints?
 forgetaboutit
  Italian for “forget about it”
  … “or die”
Data normalization? Schema?
   Foreign Keys? Column
        Constraints?
 forgetaboutit
  Italian for “forget about it”
  … “or die”
 Denormalize “until it hurts”
Data normalization? Schema?
   Foreign Keys? Column
        Constraints?
 forgetaboutit
  Italian for “forget about it”
  … “or die”
 Denormalize “until it hurts”
 But there are validations are available
Data normalization? Schema?
   Foreign Keys? Column
        Constraints?
 forgetaboutit
  Italian for “forget about it”
  … “or die”
 Denormalize “until it hurts”
 But there are validations are available
  Validates a record on update with a JS function
Required Fields
function(newDoc, oldDoc, userCtx) {
 function require(field, message) {
   message = message || "Document must have a " + field;
   if (!newDoc[field]) throw({forbidden : message});
 };

    if (newDoc.type == "blogPost") {
      require("title");
      require("created_at");
      require("body");
                                       Convention alert!
      require("author");
    } ...
}
Thank You!
Learn
http://couchdb.apache.org/
http://books.couchdb.org/relax
http://wiki.apache.org/couchdb/

Awesome posts by community
http://planet.couchdb.org

Development Libraries
http://github.com/jchris/couchrest
http://github.com/couchapp/couchapp

More Related Content

What's hot

Elasticsearch for SQL Users
Elasticsearch for SQL UsersElasticsearch for SQL Users
Elasticsearch for SQL UsersAll Things Open
 
Elasticsearch und die Java-Welt
Elasticsearch und die Java-WeltElasticsearch und die Java-Welt
Elasticsearch und die Java-WeltFlorian Hopf
 
아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문NAVER D2
 
Mito, a successor of Integral
Mito, a successor of IntegralMito, a successor of Integral
Mito, a successor of Integralfukamachi
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSMongoDB
 
Elasticsearch 설치 및 기본 활용
Elasticsearch 설치 및 기본 활용Elasticsearch 설치 및 기본 활용
Elasticsearch 설치 및 기본 활용종민 김
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryAlexandre Morgaut
 
10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators  10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators iammutex
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBUwe Printz
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data ModelingDATAVERSITY
 
Polyglot persistence with Spring Data
Polyglot persistence with Spring DataPolyglot persistence with Spring Data
Polyglot persistence with Spring DataCorneil du Plessis
 
[NodeConf.eu 2014] Scaling AB Testing on Netflix.com with Node.js
[NodeConf.eu 2014] Scaling AB Testing on Netflix.com with Node.js[NodeConf.eu 2014] Scaling AB Testing on Netflix.com with Node.js
[NodeConf.eu 2014] Scaling AB Testing on Netflix.com with Node.jsAlex Liu
 
Beyond Cookies, Persistent Storage For Web Applications Web Directions North ...
Beyond Cookies, Persistent Storage For Web Applications Web Directions North ...Beyond Cookies, Persistent Storage For Web Applications Web Directions North ...
Beyond Cookies, Persistent Storage For Web Applications Web Directions North ...BradNeuberg
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?Trisha Gee
 
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Comsysto Reply GmbH
 
Building .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase LiteBuilding .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase Litegramana
 
Solr vs. Elasticsearch - Case by Case
Solr vs. Elasticsearch - Case by CaseSolr vs. Elasticsearch - Case by Case
Solr vs. Elasticsearch - Case by CaseAlexandre Rafalovitch
 
EWD 3 Training Course Part 21: Persistent JavaScript Objects
EWD 3 Training Course Part 21: Persistent JavaScript ObjectsEWD 3 Training Course Part 21: Persistent JavaScript Objects
EWD 3 Training Course Part 21: Persistent JavaScript ObjectsRob Tweed
 

What's hot (20)

wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?
 
Elasticsearch for SQL Users
Elasticsearch for SQL UsersElasticsearch for SQL Users
Elasticsearch for SQL Users
 
Elasticsearch und die Java-Welt
Elasticsearch und die Java-WeltElasticsearch und die Java-Welt
Elasticsearch und die Java-Welt
 
아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문
 
Mito, a successor of Integral
Mito, a successor of IntegralMito, a successor of Integral
Mito, a successor of Integral
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJS
 
Elasticsearch 설치 및 기본 활용
Elasticsearch 설치 및 기본 활용Elasticsearch 설치 및 기본 활용
Elasticsearch 설치 및 기본 활용
 
Unqlite
UnqliteUnqlite
Unqlite
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators  10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDB
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
Polyglot persistence with Spring Data
Polyglot persistence with Spring DataPolyglot persistence with Spring Data
Polyglot persistence with Spring Data
 
[NodeConf.eu 2014] Scaling AB Testing on Netflix.com with Node.js
[NodeConf.eu 2014] Scaling AB Testing on Netflix.com with Node.js[NodeConf.eu 2014] Scaling AB Testing on Netflix.com with Node.js
[NodeConf.eu 2014] Scaling AB Testing on Netflix.com with Node.js
 
Beyond Cookies, Persistent Storage For Web Applications Web Directions North ...
Beyond Cookies, Persistent Storage For Web Applications Web Directions North ...Beyond Cookies, Persistent Storage For Web Applications Web Directions North ...
Beyond Cookies, Persistent Storage For Web Applications Web Directions North ...
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
 
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
 
Building .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase LiteBuilding .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase Lite
 
Solr vs. Elasticsearch - Case by Case
Solr vs. Elasticsearch - Case by CaseSolr vs. Elasticsearch - Case by Case
Solr vs. Elasticsearch - Case by Case
 
EWD 3 Training Course Part 21: Persistent JavaScript Objects
EWD 3 Training Course Part 21: Persistent JavaScript ObjectsEWD 3 Training Course Part 21: Persistent JavaScript Objects
EWD 3 Training Course Part 21: Persistent JavaScript Objects
 

Similar to Couchdb: No SQL? No driver? No problem

CouchDB : More Couch
CouchDB : More CouchCouchDB : More Couch
CouchDB : More Couchdelagoya
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchAppsBradley Holt
 
OSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBOSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBBradley Holt
 
Solutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache KafkaSolutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache KafkaGuido Schmutz
 
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache KafkaSolutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache KafkaGuido Schmutz
 
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...confluent
 
REST with Eve and Python
REST with Eve and PythonREST with Eve and Python
REST with Eve and PythonPiXeL16
 
CouchDB Open Source Bridge
CouchDB Open Source BridgeCouchDB Open Source Bridge
CouchDB Open Source BridgeChris Anderson
 
Working with disconnected data in Windows Store apps
Working with disconnected data in Windows Store appsWorking with disconnected data in Windows Store apps
Working with disconnected data in Windows Store appsAlex Casquete
 
distributing over the web
distributing over the webdistributing over the web
distributing over the webNicola Baldi
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowKarsten Dambekalns
 
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...Ivanti
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaYevgeniy Brikman
 
Benjamin Guinebertière - Microsoft Azure: Document DB and other noSQL databas...
Benjamin Guinebertière - Microsoft Azure: Document DB and other noSQL databas...Benjamin Guinebertière - Microsoft Azure: Document DB and other noSQL databas...
Benjamin Guinebertière - Microsoft Azure: Document DB and other noSQL databas...NoSQLmatters
 
Managing Your Content with Elasticsearch
Managing Your Content with ElasticsearchManaging Your Content with Elasticsearch
Managing Your Content with ElasticsearchSamantha Quiñones
 
Introduction to CouchDB
Introduction to CouchDBIntroduction to CouchDB
Introduction to CouchDBOpusVL
 

Similar to Couchdb: No SQL? No driver? No problem (20)

CouchDB : More Couch
CouchDB : More CouchCouchDB : More Couch
CouchDB : More Couch
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
Ws rest
Ws restWs rest
Ws rest
 
OSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDBOSCON 2011 Learning CouchDB
OSCON 2011 Learning CouchDB
 
Couchdb Nosql
Couchdb NosqlCouchdb Nosql
Couchdb Nosql
 
Solutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache KafkaSolutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache Kafka
 
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache KafkaSolutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
 
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
 
REST with Eve and Python
REST with Eve and PythonREST with Eve and Python
REST with Eve and Python
 
CouchDB Open Source Bridge
CouchDB Open Source BridgeCouchDB Open Source Bridge
CouchDB Open Source Bridge
 
Working with disconnected data in Windows Store apps
Working with disconnected data in Windows Store appsWorking with disconnected data in Windows Store apps
Working with disconnected data in Windows Store apps
 
distributing over the web
distributing over the webdistributing over the web
distributing over the web
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
 
Unit 02: Web Technologies (2/2)
Unit 02: Web Technologies (2/2)Unit 02: Web Technologies (2/2)
Unit 02: Web Technologies (2/2)
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Benjamin Guinebertière - Microsoft Azure: Document DB and other noSQL databas...
Benjamin Guinebertière - Microsoft Azure: Document DB and other noSQL databas...Benjamin Guinebertière - Microsoft Azure: Document DB and other noSQL databas...
Benjamin Guinebertière - Microsoft Azure: Document DB and other noSQL databas...
 
Managing Your Content with Elasticsearch
Managing Your Content with ElasticsearchManaging Your Content with Elasticsearch
Managing Your Content with Elasticsearch
 
Introduction to CouchDB
Introduction to CouchDBIntroduction to CouchDB
Introduction to CouchDB
 

More from delagoya

Nyc big datagenomics-pizarroa-sept2017
Nyc big datagenomics-pizarroa-sept2017Nyc big datagenomics-pizarroa-sept2017
Nyc big datagenomics-pizarroa-sept2017delagoya
 
Machine Learning on the Cloud with Apache MXNet
Machine Learning on the Cloud with Apache MXNetMachine Learning on the Cloud with Apache MXNet
Machine Learning on the Cloud with Apache MXNetdelagoya
 
padrino_and_sequel
padrino_and_sequelpadrino_and_sequel
padrino_and_sequeldelagoya
 
Itmat pcbi-r-course-1
Itmat pcbi-r-course-1Itmat pcbi-r-course-1
Itmat pcbi-r-course-1delagoya
 
Everything comes in 3's
Everything comes in 3'sEverything comes in 3's
Everything comes in 3'sdelagoya
 

More from delagoya (6)

Nyc big datagenomics-pizarroa-sept2017
Nyc big datagenomics-pizarroa-sept2017Nyc big datagenomics-pizarroa-sept2017
Nyc big datagenomics-pizarroa-sept2017
 
Machine Learning on the Cloud with Apache MXNet
Machine Learning on the Cloud with Apache MXNetMachine Learning on the Cloud with Apache MXNet
Machine Learning on the Cloud with Apache MXNet
 
Ruby FFI
Ruby FFIRuby FFI
Ruby FFI
 
padrino_and_sequel
padrino_and_sequelpadrino_and_sequel
padrino_and_sequel
 
Itmat pcbi-r-course-1
Itmat pcbi-r-course-1Itmat pcbi-r-course-1
Itmat pcbi-r-course-1
 
Everything comes in 3's
Everything comes in 3'sEverything comes in 3's
Everything comes in 3's
 

Recently uploaded

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Recently uploaded (20)

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

Couchdb: No SQL? No driver? No problem

  • 1. * CouchDB No SQL? No Driver? No problem. Angel Pizarro angel@upenn.edu * www.bauwel-movement.co.uk/ sculpture.php
  • 2. About Me Me: CBIL alumni! Work in mass spec proteomics Lots of data in lots of formats in bioinformatics Ruby for programming and Ruby on Rails for Web apps But that doesn’t matter for CouchDB! Interested in CouchDB for AWS deployment
  • 3. Overview Talk about Key-Value stores Introduce some general theory and concepts CouchDB specifics Example problem More CouchDB specifics Questions?
  • 4. Key-Value Databases Datastore of values indexed by keys (duh!) Hash or B-Tree index for keys Cassandra Hash is FAST, but only allows single-value lookups B-Tree is slower, but allows range queries Horizontally scalable - via key partitioning
  • 5. The CAP theory : applies when business logic is separate from storage Consistency vs. Availability vs. Partition tolerance RDBMS = enforced consistency PAXOS = quorum consistency CouchDB (and others) = eventual consistency and horizontally scalable http://www.julianbrowne.com/article/viewer/brewers-cap-theorem
  • 8. CouchDB Document Oriented Database JSON documents HTTP protocol using REST operations No direct native language drivers * Javascript is the lingua franca * Hovercraft: http://github.com/jchris/hovercraft/
  • 9. CouchDB Document Oriented Database JSON documents HTTP protocol using REST operations No direct native language drivers * Javascript is the lingua franca ACID & MVCC guarantees on a per- document basis * Hovercraft: http://github.com/jchris/hovercraft/
  • 10. CouchDB Document Oriented Database JSON documents HTTP protocol using REST operations No direct native language drivers * Javascript is the lingua franca ACID & MVCC guarantees on a per- document basis Map-Reduce indexing and views * Hovercraft: http://github.com/jchris/hovercraft/
  • 11. CouchDB Document Oriented Database JSON documents HTTP protocol using REST operations No direct native language drivers * Javascript is the lingua franca ACID & MVCC guarantees on a per- document basis Map-Reduce indexing and views Back-ups and replication are easy-peasy * Hovercraft: http://github.com/jchris/hovercraft/
  • 12. Javascript Object Notation
  • 13. Javascript Object Notation * * http://www.json.org
  • 14. Example JSON { “name”: “J. Doe”, “friends”: 0, “traits”: [“nice”, “outgoing”] }
  • 15. REST
  • 17. REST Representational State Transfer Clients-Server separation with uniform interface (HTTP)
  • 18. REST Representational State Transfer Clients-Server separation with uniform interface (HTTP) Load-balancing, caching, authorization & authentication, proxies
  • 19. REST Representational State Transfer Clients-Server separation with uniform interface (HTTP) Load-balancing, caching, authorization & authentication, proxies Stateless - client is responsible for creating a self- sufficient request
  • 20. REST Representational State Transfer Clients-Server separation with uniform interface (HTTP) Load-balancing, caching, authorization & authentication, proxies Stateless - client is responsible for creating a self- sufficient request Resources are cacheable - servers must mark non-cacheable resources as such
  • 21. REST Representational State Transfer Clients-Server separation with uniform interface (HTTP) Load-balancing, caching, authorization & authentication, proxies Stateless - client is responsible for creating a self- sufficient request Resources are cacheable - servers must mark non-cacheable resources as such Only 5 HTTP verbs
  • 22. REST Representational State Transfer Clients-Server separation with uniform interface (HTTP) Load-balancing, caching, authorization & authentication, proxies Stateless - client is responsible for creating a self- sufficient request Resources are cacheable - servers must mark non-cacheable resources as such Only 5 HTTP verbs GET, PUT, POST, DELETE, HEAD
  • 23. CouchDB REST/CRUD GET read PUT create or update DELETE delete something POST bulk operations
  • 24. CouchDB passes the ACID test Each document is completely self-sufficient Each document has a version number An update operation writes a complete new copy of the the record and is assigned the new version number Append-only file structure allows the write to occur while still serving read requests
  • 25. MVCC RDBMS CouchDB Multi-Version Concurrency Control RDBMS enforces consistency using read/write locks Instead of locks, CouchDB just serve up old data Multi-document (mutli-row) transactional semantics must be handled by the application
  • 26. Database API Create a DB: $ curl -X PUT http://127.0.0.1:5984/friendbook {"ok":true}
  • 27. Database API Create a DB: Protocol $ curl -X PUT http://127.0.0.1:5984/friendbook {"ok":true}
  • 28. Database API Create a DB: CouchDB server $ curl -X PUT http://127.0.0.1:5984/friendbook {"ok":true}
  • 29. Database API Create a DB: DB name $ curl -X PUT http://127.0.0.1:5984/friendbook {"ok":true}
  • 30. Database API Create a DB: $ curl -X PUT http://127.0.0.1:5984/friendbook {"ok":true} Try it Again: {"error":"db_exists"}
  • 31. Database API Create a DB: $ curl -X PUT http://127.0.0.1:5984/friendbook {"ok":true} Try it Again: {"error":"db_exists"} Not recoverable! Delete a DB: $ curl -X DELETE http://localhost:5984/friendbook {"ok":true}
  • 32. Inserting a document All insert require that you give a unique ID. You can request one from CouchDB: $ curl -X GET http://localhost:5984/_uuids {"uuids":["d1dde0996a4db7c1ebc78fb89c01b9e6"]}
  • 33. Inserting a document All insert require that you give a unique ID. You can request one from CouchDB: $ curl -X GET http://localhost:5984/_uuids {"uuids":["d1dde0996a4db7c1ebc78fb89c01b9e6"]} We’ll just give one: $ curl -X PUT http://localhost:5984/friendbook/j_doe -d @j_doe.json {"ok":true, "id":"j_doe", "rev":"1-062af1c4ac73287b7e07396c86243432"}
  • 34. Inserting a document All insert require that you give a unique ID. You can request one from CouchDB: $ curl -X GET http://localhost:5984/_uuids {"uuids":["d1dde0996a4db7c1ebc78fb89c01b9e6"]} We’ll just give one: $ curl -X PUT http://localhost:5984/friendbook/j_doe -d @j_doe.json Read a JSON file {"ok":true, "id":"j_doe", "rev":"1-062af1c4ac73287b7e07396c86243432"}
  • 35. Full JSON document Before { "name": "J. Doe", "friends": 0 } After { "_id": "j_doe", "_rev": "1-062af1c4ac73287b7e07396c86243432", "name": "J. Doe", "friends": 0 }
  • 36. Updating a document $ curl -X PUT http://localhost:5984/friendbook/j_doe -d '{"name": "J. Doe", "friends": 1 }' {"error":"conflict","reason":"Document update conflict."}
  • 37. Updating a document $ curl -X PUT http://localhost:5984/friendbook/j_doe -d '{"name": "J. Doe", "friends": 1 }' {"error":"conflict","reason":"Document update conflict."} Must give _rev (revision number) for updates! revised.json { "_rev":"1-062af1c4ac73287b7e07396c86243432", "name":"J. Doe", "friends": 1 } $ curl -X PUT http://localhost:5984/friendbook/j_doe -d @revised.json {"ok":true,"id":"j_doe","rev":"2-0629239b53a8d146a3a3c4c63e 2dbfd0"}
  • 38. Deleting a document $ curl -X DELETE http://localhost:5984/friendbook/j_doe {"error":"conflict","reason":"Document update conflict."} Must give revision number for deletes! $ curl -X DELETE http://localhost:5984/friendbook/j_doe? rev=2-0629239b53a8d146a3a3c4c63e2dbfd0 {"ok":true,"id":"j_doe", "rev":"3-57673a4b7b662bb916cc374a92318c6b"} Returns a revision number for the delete $ curl -X GET http://localhost:5984/friendbook/j_doe {"error":"not_found","reason":"deleted"}
  • 39. Bulk operation POST /database/_bulk_docs with a JSON document containing all of the new or updated documents. // documents to bulk upload { "docs": [ {"_id": "0", "integer": 0, "string": "0"}, {"_id": "1", "integer": 1, "string": "1"}, {"_id": "2", "integer": 2, "string": "2"} ] // reply from CouchDB } [ {"id":"0","rev":"1-62657917"}, {"id":"1","rev":"1-2089673485"}, {"id":"2","rev":"1-2063452834"} ]
  • 40. GOTCHA’s! Version storage is not guaranteed! Do not use this as a VCS! POST to /db/_compact deletes all older vesions To “roll back a transaction” you must: Retrieve all related records, cache these Insert any updates to records. On failure, use the returned revision numbers to re-insert the older record as a new one
  • 42. Our Example Problem Hello world? Blog? Twitter clone?
  • 43. Our Example Problem Hello world? Blog? Twitter clone? Let’s store all human proteins instead
  • 44. Our Example Problem Hello world? Blog? Twitter clone? Let’s store all human proteins instead LOCUS YP_003024029 227 aa linear PRI 09-JUL-2009 DEFINITION cytochrome c oxidase subunit II [Homo sapiens]. ACCESSION YP_003024029 VERSION YP_003024029.1 GI:251831110 DBLINK Project:30353 DBSOURCE REFSEQ: accession NC_012920.1 KEYWORDS . SOURCE mitochondrion Homo sapiens (human) ORGANISM Homo sapiens Eukaryota; Metazoa; Chordata; Craniata; Vertebrata; Euteleostomi; Mammalia; Eutheria; Euarchontoglires; Primates; Haplorrhini; Catarrhini; Hominidae; Homo.
  • 45. Our Example Problem Hello world? Blog? Twitter clone? Let’s store all human proteins instead LOCUS YP_003024029 227 aa linear PRI 09-JUL-2009 DEFINITION cytochrome c oxidase subunit II [Homo sapiens]. ACCESSION YP_003024029 VERSION YP_003024029.1 GI:251831110 DBLINK Project:30353 FEATURES DBSOURCE REFSEQ: accession NC_012920.1 Location/Qualifiers KEYWORDS . source 1..227 SOURCE /organism="Homo sapiens" mitochondrion Homo sapiens (human) ORGANISM Homo sapiens /organelle="mitochondrion" /isolation_source="caucasian" Eukaryota; Metazoa; Chordata; Craniata; Vertebrata; Euteleostomi; /db_xref="taxon:9606" Mammalia; Eutheria; Euarchontoglires; Primates; Haplorrhini; Catarrhini; Hominidae; Homo./tissue_type="placenta" /country="United Kingdom: Great Britain" /note="this is the rCRS" Protein 1..227 /product="cytochrome c oxidase subunit II" /calculated_mol_wt=25434 http://www.ncbi.nlm.nih.gov/
  • 46. Our Example Problem Hello world? Blog? Twitter clone? Let’s store all human proteins instead LOCUS YP_003024029 227 aa linear PRI 09-JUL-2009 DEFINITION cytochrome c oxidase subunit II [Homo sapiens]. ACCESSION YP_003024029 VERSION YP_003024029.1 GI:251831110 DBLINK Project:30353 FEATURES DBSOURCE REFSEQ: accession NC_012920.1 Location/Qualifiers KEYWORDS . source 1..227 SOURCE /organism="Homo sapiens" mitochondrion Homo sapiens (human) ORGANISM Homo sapiens /organelle="mitochondrion" /isolation_source="caucasian" Eukaryota; Metazoa; Chordata; Craniata; Vertebrata; Euteleostomi; /db_xref="taxon:9606" Mammalia; Eutheria; Euarchontoglires; Primates; Haplorrhini; Catarrhini; Hominidae; Homo./tissue_type="placenta" /country="United Kingdom: Great Britain" /note="this is the rCRS" Protein 1..227 /product="cytochrome c oxidase subunit II" /calculated_mol_wt=25434 http://www.ncbi.nlm.nih.gov/
  • 47. Futon : A Couchapp
  • 48. Futon : A Couchapp
  • 49. Futon : A Couchapp
  • 50. Futon : A Couchapp This one is going to be a bit tougher
  • 52. Design Documents The key to using CouchDB as more than a key-value store
  • 53. Design Documents The key to using CouchDB as more than a key-value store Just another JSON document, but contain javascript functions that CouchDB treats as application code Functions are executed within CouchDB
  • 54. Design Documents The key to using CouchDB as more than a key-value store Just another JSON document, but contain javascript functions that CouchDB treats as application code Functions are executed within CouchDB Contain sections for map-reduce views, data validation, alternate formatting, ... Also library code & data structures specific to the design document
  • 56. Soy Map! Views use a Map-Reduce model for indexing and defining “virtual” documents Fits well with assumptions of self-sufficient documents and eventual consistency
  • 57. Soy Map! Views use a Map-Reduce model for indexing and defining “virtual” documents Fits well with assumptions of self-sufficient documents and eventual consistency Map function is applied to all documents in the database Emits (parts of) documents that pass mustard Indexing is incremental after an initial definition You can choose to defer an index update for insert speed
  • 64. GET by the indexed key
  • 65. GET by the indexed key GET /refseq_human/_design/gb/_view/dbXref?key="GeneID:10" {"total_rows":7,"offset":2,"rows":[ {"id":"NP_000006", "key":"GeneID:10", "value":"NP_000006"} ]}
  • 66. Reduce functions Optional and used in concert with a specific map function Great for summarizing or collating numerical data points E.g. counts, number of over time X, average load, probability of conversion Not really applicable to our example, so we’ll not cover it today
  • 67. Show me the ... HTML? JSON is great, but what about, ya know, something useful? You can make a separate app to reformat the JSON OR you can use the “shows” section of a _design document. Rich formating possible with functions, templates, and special include macros
  • 68. FASTA format “shows” : { “fasta” : “function(doc, req) { return ‘>’ + doc._id + ‘n’ + doc.seq; }”, ...
  • 69. FASTA format “shows” : { “fasta” : “function(doc, req) { return ‘>’ + doc._id + ‘n’ + doc.seq; }”, ... GET /refseq_human/_design/gb/_show/fasta/NP_000006 >NP_000006 MDIEAYFERIGYKNSRNKLDLETLTDILEHQIRAVPFENLNMHCGQAMELGLEAIFDHIVRR NRGGWCLQVNQLLYWALTTIGFQTTMLGGYFYIPPVNKYSTGMVHLLLQVTIDGRNYIV DAGSGSSSQMWQPLELISGKDQPQVPCIFCLTEERGIWYLDQIRREQYITNKEFLNSHLLPK KKHQKIYLFTLEPRTIEDFESMNTYLQTSPTSSFITTSFCSLQTPEGVYCLVGFILTYRKFNYKD NTDLVEFKTLTEEEVEEVLRNIFKISLGRNLVPKPGDGSLTI
  • 71. Backups & Replication Backup: simply copy the database file
  • 72. Backups & Replication Backup: simply copy the database file Replicate: send a POST request with a source and target database
  • 73. Backups & Replication Backup: simply copy the database file Replicate: send a POST request with a source and target database Source and target DB’s can either be local (just the db name) or remote (full URL)
  • 74. Backups & Replication Backup: simply copy the database file Replicate: send a POST request with a source and target database Source and target DB’s can either be local (just the db name) or remote (full URL) “continous”: true option will register the target to the source’s _changes notification API
  • 75. Backups & Replication Backup: simply copy the database file Replicate: send a POST request with a source and target database Source and target DB’s can either be local (just the db name) or remote (full URL) “continous”: true option will register the target to the source’s _changes notification API $ curl -X POST http://localhost:5984/_replicate -d '{"source":"db", "target":"db-replica", "continuous":true}'
  • 76. Data normalization? Schema? Foreign Keys? Column Constraints?
  • 77. Data normalization? Schema? Foreign Keys? Column Constraints? forgetaboutit Italian for “forget about it” … “or die”
  • 78. Data normalization? Schema? Foreign Keys? Column Constraints? forgetaboutit Italian for “forget about it” … “or die” Denormalize “until it hurts”
  • 79. Data normalization? Schema? Foreign Keys? Column Constraints? forgetaboutit Italian for “forget about it” … “or die” Denormalize “until it hurts” But there are validations are available
  • 80. Data normalization? Schema? Foreign Keys? Column Constraints? forgetaboutit Italian for “forget about it” … “or die” Denormalize “until it hurts” But there are validations are available Validates a record on update with a JS function
  • 81. Required Fields function(newDoc, oldDoc, userCtx) { function require(field, message) { message = message || "Document must have a " + field; if (!newDoc[field]) throw({forbidden : message}); }; if (newDoc.type == "blogPost") { require("title"); require("created_at"); require("body"); Convention alert! require("author"); } ... }
  • 82. Thank You! Learn http://couchdb.apache.org/ http://books.couchdb.org/relax http://wiki.apache.org/couchdb/ Awesome posts by community http://planet.couchdb.org Development Libraries http://github.com/jchris/couchrest http://github.com/couchapp/couchapp

Editor's Notes

  1. - If the key is a DateTime, then B-tree is a much better choice
  2. Brewer’s CAP Theorem http://www.julianbrowne.com/article/viewer/brewers-cap-theorem Partition tolerance encompasses both business logic and data partitioning. PAXOS will override more recent updates to a disconnected resource if it did not vote on a previous transaction.
  3. Highlighted words covered later in order that they appear
  4. Highlighted words covered later in order that they appear
  5. Highlighted words covered later in order that they appear
  6. Highlighted words covered later in order that they appear
  7. Highlighted words covered later in order that they appear
  8. Highlighted words covered later in order that they appear
  9. Other stuff, but this is the most relevant for the discussion Older browsers only support green verbs
  10. Other stuff, but this is the most relevant for the discussion Older browsers only support green verbs
  11. Other stuff, but this is the most relevant for the discussion Older browsers only support green verbs
  12. Other stuff, but this is the most relevant for the discussion Older browsers only support green verbs
  13. Other stuff, but this is the most relevant for the discussion Older browsers only support green verbs
  14. Other stuff, but this is the most relevant for the discussion Older browsers only support green verbs
  15. Other stuff, but this is the most relevant for the discussion Older browsers only support green verbs
  16. CRUD = Create Read Update Delete
  17. Next is the API discussions
  18. You can give a “count” parameter to UUID function: $ curl -X GET http://localhost:5984/_uuids?count=10
  19. You can give a “count” parameter to UUID function: $ curl -X GET http://localhost:5984/_uuids?count=10
  20. Can give it as an URL parameter or in the E-Tag HTTP header. You cannot delete a specific revision! The revision number is only there so that the server can definitively say you are talking about the most recent record. You need delete rev for replication of delete operations on other servers that are being synced to this one.
  21. Might also be able to delete a particualr version. Will have to check that.
  22. Note: I could’ve made GI a number, but did not in this case Zipcodes would be a bad thing to turn into numbers, b/c of possible leading zeros
  23. Note: I could’ve made GI a number, but did not in this case Zipcodes would be a bad thing to turn into numbers, b/c of possible leading zeros
  24. Note: I could’ve made GI a number, but did not in this case Zipcodes would be a bad thing to turn into numbers, b/c of possible leading zeros
  25. Best practice = One design document per application or set of requirements Next: Map-Reduce Views
  26. Best practice = One design document per application or set of requirements Next: Map-Reduce Views
  27. Best practice = One design document per application or set of requirements Next: Map-Reduce Views
  28. We are just going to take a look at a simple plain text example of FASTA file
  29. Append-only file structure ensures that your DB is always valid, even during mid-write server failures.
  30. Append-only file structure ensures that your DB is always valid, even during mid-write server failures.
  31. Append-only file structure ensures that your DB is always valid, even during mid-write server failures.
  32. Append-only file structure ensures that your DB is always valid, even during mid-write server failures.
  33. Append-only file structure ensures that your DB is always valid, even during mid-write server failures.