SlideShare a Scribd company logo
1 of 53
Download to read offline
CouchDB
A Database for the Web




Jonathan Weiss
Who am I?

Working for Peritor in Berlin, Germany

Written, maintain, or involved in
   Webistrano
   Capistrano
   SimplyStored
   Happening
   The great fire of London

http://github.com/jweiss

@jweiss




                                         2
Scalarium


Amazon EC2 Cluster Management
   Auto-config
   Self-Healing
   Auto-Scaling
   One-click-deployment




www.scalarium.com




                                3
Database Requirements


High Availability

Easy Replication

Clustering

Robustness

Short Recovery Time




                        4
5
CouchDB


Build for the Web

Scales

Replication built-in

Embracing offline

Flexible schema – document DB




                                6
”CouchDB is built of the Web“
               Jacob Kaplan-Moss




                                   7
Web Technologies

HTTP
 the access protocol



JavaScript
  the query language



JSON
  the storage format




                       8
JSON Document

 {
     "_id": "BCCD12CBB",
     "_rev": "1-AB764C",
     "type": "person",
     "name": "Darth Vader",
     "age": 63,
     "headware": ["Helmet", "Sombrero"],
     "dark_side": true,
     "weapons": {
       "right_arm": "light_saber",
       "left_arm": null
     }
 }
                                           9
JSON Document

 {
     "_id": "BCCD12CBB",
     "_rev": "1-AB764C",
     "type": "person",
     "name": "Darth Vader",
     "age": 63,
     "headware": ["Helmet", "Sombrero"],
     "dark_side": true,
     "weapons": {
       "right_arm": "light_saber",
       "left_arm": null
     }
 }
                                           10
JSON Document

 {
     "_id": "BCCD12CBB",
     "_rev": "1-AB764C",
     "type": "person",
     "name": "Darth Vader",
     "age": 63,
     "headware": ["Helmet", "Sombrero"],
     "dark_side": true,
     "weapons": {
       "right_arm": "light_saber",
       "left_arm": null
     }
 }
                                           11
No Tables or Namespaces




                          12
No Tables or Namespaces




                          13
Manual Namespacing

 {
     "_id": "BCCD12CBB",
     "_rev": "1-AB764C",
     "type": "person",
     "name": "Darth Vader",
     "age": 63,
     "headware": ["Helmet", "Sombrero"],
     "dark_side": true,
     "weapons": {
       "right_arm": "light_saber",
       "left_arm": null
     }
 }
                                           14
Interacting with CouchDB




                   JSON


HTTP Client

              PUT /dbname/ID



                               15
Interacting with CouchDB



              GET /dbname/ID



HTTP Client



                   JSON


                               16
Interacting with CouchDB




              DELETE /dbname/ID
HTTP Client




                                  17
Views




        18
Design Document
 {
     "id": "_design/hats”,
     "_rev": "431212AB4”,
     "language": "javascript”,
     "views": {
       "all": {
         "map": "function(doc){ .... }”,
         "reduce": "function(doc){ .... }”
       },
     "by_manufacturer": {
       "map": "function(doc){ .... }”,
       "reduce": "function(doc){ .... }”
       }
     }
 }                                           19
Design Document
 {                                               Document ID
     "id": "_design/hats”,                            –
     "_rev": "431212AB4”,                    prefixed by “_design/”
     "language": "javascript”,
     "views": {
       "all": {
         "map": "function(doc){ .... }”,
         "reduce": "function(doc){ .... }”
       },
     "by_manufacturer": {
       "map": "function(doc){ .... }”,
       "reduce": "function(doc){ .... }”
       }
     }
 }                                                                   20
Design Document
 {
     "id": "_design/hats”,
     "_rev": "431212AB4”,
     "language": "javascript”,
     "views": {
       "all": {                              Hash of Views
         "map": "function(doc){ .... }”,
         "reduce": "function(doc){ .... }”
       },
     "by_manufacturer": {
       "map": "function(doc){ .... }”,
       "reduce": "function(doc){ .... }”
       }
     }
 }                                                           21
Design Document
 {
     "id": "_design/hats”,
     "_rev": "431212AB4”,
     "language": "javascript”,
     "views": {
       "all": {                                  Hash of Views
         "map": "function(doc){ .... }”,     Every view has map &
         "reduce": "function(doc){ .... }”      reduce function
       },
     "by_manufacturer": {
       "map": "function(doc){ .... }”,
       "reduce": "function(doc){ .... }”
       }
     }
 }                                                                  22
Map



function(doc) {
    if (doc.headware) {
      for (var hat in doc.headware) {
        emit(hat, 1);
      }
    }
}



                                        23
Map
                                  Passed every
                               document in the DB

function(doc) {
    if (doc.headware) {
      for (var hat in doc.headware) {
        emit(hat, 1);
      }
    }
}



                                                    24
Map



function(doc) {
    if (doc.headware) {
                                        Inspects
      for (var hat in doc.headware) {   & Decides
        emit(hat, 1);
      }
    }
}



                                                    25
Map



function(doc) {
    if (doc.headware) {
      for (var hat in doc.headware) {
        emit(hat, 1);
      }
    }                          Emits result
}                                 for index




                                              26
Reduce



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




                                      27
Reduce
                                     Passed map result
                                  (or partial reduce result)

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




                                                               28
Reduce



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




           Aggregates
     (count, sum, average, …)



                                      29
Example Map Result

Map functions are similar to SQL indices

                ID               KEY         VALUE

         51ABFA211         Cap                  1

         ABC123456         Cappy                1

         BCCD12CBB         Helmet               1

         BCCD12CBB         Sombrero             1

Sorted by the key

Key can also be an array

Value can be complex JSON and/or reference to other document
                                                               30
Query a view


        GET /dbname/_design/hats/_view/all




HTTP Client


              {"total_rows":348,"offset":0,"rows”:[
                {"id":"A","key":"A","value":1},
                {"id":"B","key":"B","value":1},
              ]}
                                                      31
Query a view


       GET /dbname/_design/hats/_view/all?
        include_docs=true




HTTP Client




                                             32
View Query


Filter by
   key=ABC123
   startkey=123 & endkey=9
   limit=100
   descending=true
   group=true
   reduce=true
   Include_docs=true




                              33
SQL vs. JavaScript




                     Vs.




                           34
Using Couch from PHP


Several options available
   PHPillow:
    http://arbitracker.org/phpillow.html (LGPL 3)
   PHP Object_Freezer:
    https://github.com/sebastianbergmann/php-object-freezer/tree (BSD)
   PHP On Couch:
    http://github.com/dready92/PHP-on-Couch/tree/master (GPLv2 or v3)
   PHP CouchDB Extension:
    http://www.topdog.za.net/php_couchdb_extension (PHP License 3.0)
   Sag for CouchDB:
   http://www.saggingcouch.com/ (Apache License 2.0)


                                                                         35
36
37
38
39
SimplyStored


CouchDB convenience Layer for Ruby
   Models & Associations
   Validations
   Callbacks               BSD-licensed on
   Dynamic finder           http://github.com/peritor/simply_stored
   S3 attachments          On top of CouchPotato, CouchRest & RestClient
   Paranoid delete
   ActiveModel compliant




                                                                            40
Many more




Or just build your own using HTTP!

                                     41
Database Requirements


High Availability

Easy Replication

Clustering

Robustness

Short Recovery Time




                        42
Replication
   B-Tree
XXXXX




              Photo by Mathias Meyer
                                       43
B-Tree

Append only

Concurrency (MVCC)

Crash resistant

Hot backups

Compaction




                     44
Replication




              45
CouchDB Replication



                      POST /_replicate




                      POST /_replicate


Eventually consistent & conflict resolution

                                             46
Load Balancing




                             Replication


 HTTP Client     HTTP Load
                 Balancer




                                           47
Caching




 HTTP Client   HTTP Cache
               Varnish
               Apache
               …




                            48
Multi-Master




               49
BigCouch

  Clustered CouchDB:

 Many CouchDBs appear as one



  Modeled after Amazon Dynamo

  Scalability like Cassandra or Riak

  github.com/cloudant/bigcouch




                                        50
Q – No. of partitions

BigCouch
N – No. of replicas

R – Read quorum

W – Write quorum




                        51
Various

CouchApps

Validations

Filtered replication

Changes feed

List functions

Futon

Geo

Fulltext-Search with embedded Lucene

Different experimental View-Server
                                       52
Q&A
Peritor GmbH
Blücherstr. 22, Hof III Aufgang 6
10961 Berlin
Tel.: +49 (0)30 69 20 09 84 0
Fax: +49 (0)30 69 20 09 84 9
Internet: www.peritor.com
E-Mail: info@peritor.com



© Peritor GmbH - Alle Rechte vorbehalten

More Related Content

What's hot

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBAlex Bilbie
 
Back to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationBack to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationMongoDB
 
Beyond the Basics 2: Aggregation Framework
Beyond the Basics 2: Aggregation Framework Beyond the Basics 2: Aggregation Framework
Beyond the Basics 2: Aggregation Framework MongoDB
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMetatagg Solutions
 
The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation FrameworkMongoDB
 
Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2MongoDB
 
2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introductionantoinegirbal
 
PhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHPPhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHPichikaway
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation FrameworkCaserta
 
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkBack to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkMongoDB
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchAppsBradley Holt
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDBNate Abele
 
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2MongoDB
 
Visualizing Web Data Query Results
Visualizing Web Data Query ResultsVisualizing Web Data Query Results
Visualizing Web Data Query ResultsAnja Jentzsch
 
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation FrameworkConceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation FrameworkMongoDB
 

What's hot (19)

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Back to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationBack to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB Application
 
Beyond the Basics 2: Aggregation Framework
Beyond the Basics 2: Aggregation Framework Beyond the Basics 2: Aggregation Framework
Beyond the Basics 2: Aggregation Framework
 
MongoDB
MongoDBMongoDB
MongoDB
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg Solutions
 
Querying mongo db
Querying mongo dbQuerying mongo db
Querying mongo db
 
MongoDB at GUL
MongoDB at GULMongoDB at GUL
MongoDB at GUL
 
The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation Framework
 
Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2Agg framework selectgroup feb2015 v2
Agg framework selectgroup feb2015 v2
 
2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction
 
PhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHPPhpstudyTokyo MongoDB PHP CakePHP
PhpstudyTokyo MongoDB PHP CakePHP
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkBack to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation Framework
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
Mongo db presentation
Mongo db presentationMongo db presentation
Mongo db presentation
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
 
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
 
Visualizing Web Data Query Results
Visualizing Web Data Query ResultsVisualizing Web Data Query Results
Visualizing Web Data Query Results
 
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation FrameworkConceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
 

Viewers also liked

CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
Introduction to couchdb
Introduction to couchdbIntroduction to couchdb
Introduction to couchdbiammutex
 
The ROI of Enhancing Your Candidate Experience
The ROI of Enhancing Your Candidate ExperienceThe ROI of Enhancing Your Candidate Experience
The ROI of Enhancing Your Candidate ExperienceTincup & Co.
 

Viewers also liked (7)

CouchDB
CouchDBCouchDB
CouchDB
 
Couchdb
CouchdbCouchdb
Couchdb
 
CouchDB
CouchDBCouchDB
CouchDB
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Introduction to couchdb
Introduction to couchdbIntroduction to couchdb
Introduction to couchdb
 
The ROI of Enhancing Your Candidate Experience
The ROI of Enhancing Your Candidate ExperienceThe ROI of Enhancing Your Candidate Experience
The ROI of Enhancing Your Candidate Experience
 
CouchDB introduction
CouchDB introductionCouchDB introduction
CouchDB introduction
 

Similar to NoSQL - An introduction to CouchDB

CouchDB on Rails - FrozenRails 2010
CouchDB on Rails - FrozenRails 2010CouchDB on Rails - FrozenRails 2010
CouchDB on Rails - FrozenRails 2010Jonathan Weiss
 
CouchDB on Rails - RailsWayCon 2010
CouchDB on Rails - RailsWayCon 2010CouchDB on Rails - RailsWayCon 2010
CouchDB on Rails - RailsWayCon 2010Jonathan Weiss
 
CouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourCouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourPeter Friese
 
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & AggregationWebinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & AggregationMongoDB
 
1403 app dev series - session 5 - analytics
1403   app dev series - session 5 - analytics1403   app dev series - session 5 - analytics
1403 app dev series - session 5 - analyticsMongoDB
 
Couchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problemCouchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problemdelagoya
 
Dart, unicorns and rainbows
Dart, unicorns and rainbowsDart, unicorns and rainbows
Dart, unicorns and rainbowschrisbuckett
 
Dart structured web apps
Dart   structured web appsDart   structured web apps
Dart structured web appschrisbuckett
 
MongoDB Live Hacking
MongoDB Live HackingMongoDB Live Hacking
MongoDB Live HackingTobias Trelle
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik ErlandsonDatabricks
 
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
 
Philipp Krenn "Make Your Data FABulous"
Philipp Krenn "Make Your Data FABulous"Philipp Krenn "Make Your Data FABulous"
Philipp Krenn "Make Your Data FABulous"Fwdays
 
Living the Nomadic life - Nic Jackson
Living the Nomadic life - Nic JacksonLiving the Nomadic life - Nic Jackson
Living the Nomadic life - Nic JacksonParis Container Day
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsInfrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsMykyta Protsenko
 
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
 
Philipp Krenn | Make Your Data FABulous | Codemotion Madrid 2018
Philipp Krenn | Make Your Data FABulous | Codemotion Madrid 2018Philipp Krenn | Make Your Data FABulous | Codemotion Madrid 2018
Philipp Krenn | Make Your Data FABulous | Codemotion Madrid 2018Codemotion
 
Webinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation OptionsWebinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation OptionsMongoDB
 
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's PerspectiveTearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's PerspectiveSeh Hui Leong
 

Similar to NoSQL - An introduction to CouchDB (20)

CouchDB on Rails
CouchDB on RailsCouchDB on Rails
CouchDB on Rails
 
CouchDB on Rails - FrozenRails 2010
CouchDB on Rails - FrozenRails 2010CouchDB on Rails - FrozenRails 2010
CouchDB on Rails - FrozenRails 2010
 
CouchDB on Rails - RailsWayCon 2010
CouchDB on Rails - RailsWayCon 2010CouchDB on Rails - RailsWayCon 2010
CouchDB on Rails - RailsWayCon 2010
 
CouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourCouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 Hour
 
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & AggregationWebinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
 
1403 app dev series - session 5 - analytics
1403   app dev series - session 5 - analytics1403   app dev series - session 5 - analytics
1403 app dev series - session 5 - analytics
 
Couchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problemCouchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problem
 
Dart, unicorns and rainbows
Dart, unicorns and rainbowsDart, unicorns and rainbows
Dart, unicorns and rainbows
 
Dart structured web apps
Dart   structured web appsDart   structured web apps
Dart structured web apps
 
MongoDB Live Hacking
MongoDB Live HackingMongoDB Live Hacking
MongoDB Live Hacking
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik Erlandson
 
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...
 
Philipp Krenn "Make Your Data FABulous"
Philipp Krenn "Make Your Data FABulous"Philipp Krenn "Make Your Data FABulous"
Philipp Krenn "Make Your Data FABulous"
 
Living the Nomadic life - Nic Jackson
Living the Nomadic life - Nic JacksonLiving the Nomadic life - Nic Jackson
Living the Nomadic life - Nic Jackson
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsInfrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and Ops
 
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
 
Philipp Krenn | Make Your Data FABulous | Codemotion Madrid 2018
Philipp Krenn | Make Your Data FABulous | Codemotion Madrid 2018Philipp Krenn | Make Your Data FABulous | Codemotion Madrid 2018
Philipp Krenn | Make Your Data FABulous | Codemotion Madrid 2018
 
Webinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation OptionsWebinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation Options
 
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's PerspectiveTearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
Tearing the Sofa Apart: CouchDB and CouchApps from a Beginner's Perspective
 

More from Jonathan Weiss

Docker on AWS OpsWorks
Docker on AWS OpsWorksDocker on AWS OpsWorks
Docker on AWS OpsWorksJonathan Weiss
 
ChefConf 2014 - AWS OpsWorks Under The Hood
ChefConf 2014 - AWS OpsWorks Under The HoodChefConf 2014 - AWS OpsWorks Under The Hood
ChefConf 2014 - AWS OpsWorks Under The HoodJonathan Weiss
 
AWS OpsWorks & Chef at the Hamburg Chef User Group 2014
AWS OpsWorks & Chef at the Hamburg Chef User Group 2014AWS OpsWorks & Chef at the Hamburg Chef User Group 2014
AWS OpsWorks & Chef at the Hamburg Chef User Group 2014Jonathan Weiss
 
DevOpsDays Amsterdam - Observations in the cloud
DevOpsDays Amsterdam - Observations in the cloudDevOpsDays Amsterdam - Observations in the cloud
DevOpsDays Amsterdam - Observations in the cloudJonathan Weiss
 
Introduction to Backbone.js
Introduction to Backbone.jsIntroduction to Backbone.js
Introduction to Backbone.jsJonathan Weiss
 
Build your own clouds with Chef and MCollective
Build your own clouds with Chef and MCollectiveBuild your own clouds with Chef and MCollective
Build your own clouds with Chef and MCollectiveJonathan Weiss
 
NoSQL - Motivation and Overview
NoSQL - Motivation and OverviewNoSQL - Motivation and Overview
NoSQL - Motivation and OverviewJonathan Weiss
 
Amazon EC2 in der Praxis
Amazon EC2 in der PraxisAmazon EC2 in der Praxis
Amazon EC2 in der PraxisJonathan Weiss
 
Infrastructure Automation with Chef
Infrastructure Automation with ChefInfrastructure Automation with Chef
Infrastructure Automation with ChefJonathan Weiss
 
Rails in the Cloud - Experiences from running on EC2
Rails in the Cloud - Experiences from running on EC2Rails in the Cloud - Experiences from running on EC2
Rails in the Cloud - Experiences from running on EC2Jonathan Weiss
 
NoSQL - Post-Relational Databases - BarCamp Ruhr3
NoSQL - Post-Relational Databases - BarCamp Ruhr3NoSQL - Post-Relational Databases - BarCamp Ruhr3
NoSQL - Post-Relational Databases - BarCamp Ruhr3Jonathan Weiss
 
Ruby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChairRuby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChairJonathan Weiss
 
No SQL - BarCamp Nürnberg 2010
No SQL - BarCamp Nürnberg 2010No SQL - BarCamp Nürnberg 2010
No SQL - BarCamp Nürnberg 2010Jonathan Weiss
 
BarCamp Nürnberg - Infrastructure As A Service
BarCamp Nürnberg - Infrastructure As A ServiceBarCamp Nürnberg - Infrastructure As A Service
BarCamp Nürnberg - Infrastructure As A ServiceJonathan Weiss
 

More from Jonathan Weiss (20)

Docker on AWS OpsWorks
Docker on AWS OpsWorksDocker on AWS OpsWorks
Docker on AWS OpsWorks
 
ChefConf 2014 - AWS OpsWorks Under The Hood
ChefConf 2014 - AWS OpsWorks Under The HoodChefConf 2014 - AWS OpsWorks Under The Hood
ChefConf 2014 - AWS OpsWorks Under The Hood
 
AWS OpsWorks & Chef at the Hamburg Chef User Group 2014
AWS OpsWorks & Chef at the Hamburg Chef User Group 2014AWS OpsWorks & Chef at the Hamburg Chef User Group 2014
AWS OpsWorks & Chef at the Hamburg Chef User Group 2014
 
DevOpsDays Amsterdam - Observations in the cloud
DevOpsDays Amsterdam - Observations in the cloudDevOpsDays Amsterdam - Observations in the cloud
DevOpsDays Amsterdam - Observations in the cloud
 
Amazon SWF and Gordon
Amazon SWF and GordonAmazon SWF and Gordon
Amazon SWF and Gordon
 
Introduction to Backbone.js
Introduction to Backbone.jsIntroduction to Backbone.js
Introduction to Backbone.js
 
Scalarium and CouchDB
Scalarium and CouchDBScalarium and CouchDB
Scalarium and CouchDB
 
Build your own clouds with Chef and MCollective
Build your own clouds with Chef and MCollectiveBuild your own clouds with Chef and MCollective
Build your own clouds with Chef and MCollective
 
NoSQL - Motivation and Overview
NoSQL - Motivation and OverviewNoSQL - Motivation and Overview
NoSQL - Motivation and Overview
 
Running on Amazon EC2
Running on Amazon EC2Running on Amazon EC2
Running on Amazon EC2
 
Amazon EC2 in der Praxis
Amazon EC2 in der PraxisAmazon EC2 in der Praxis
Amazon EC2 in der Praxis
 
Infrastructure Automation with Chef
Infrastructure Automation with ChefInfrastructure Automation with Chef
Infrastructure Automation with Chef
 
Rails in the Cloud
Rails in the CloudRails in the Cloud
Rails in the Cloud
 
EventMachine
EventMachineEventMachine
EventMachine
 
Rails in the Cloud - Experiences from running on EC2
Rails in the Cloud - Experiences from running on EC2Rails in the Cloud - Experiences from running on EC2
Rails in the Cloud - Experiences from running on EC2
 
NoSQL - Post-Relational Databases - BarCamp Ruhr3
NoSQL - Post-Relational Databases - BarCamp Ruhr3NoSQL - Post-Relational Databases - BarCamp Ruhr3
NoSQL - Post-Relational Databases - BarCamp Ruhr3
 
Ruby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChairRuby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChair
 
No SQL - BarCamp Nürnberg 2010
No SQL - BarCamp Nürnberg 2010No SQL - BarCamp Nürnberg 2010
No SQL - BarCamp Nürnberg 2010
 
BarCamp Nürnberg - Infrastructure As A Service
BarCamp Nürnberg - Infrastructure As A ServiceBarCamp Nürnberg - Infrastructure As A Service
BarCamp Nürnberg - Infrastructure As A Service
 
Rails Security
Rails SecurityRails Security
Rails Security
 

NoSQL - An introduction to CouchDB

  • 1. CouchDB A Database for the Web Jonathan Weiss
  • 2. Who am I? Working for Peritor in Berlin, Germany Written, maintain, or involved in   Webistrano   Capistrano   SimplyStored   Happening   The great fire of London http://github.com/jweiss @jweiss 2
  • 3. Scalarium Amazon EC2 Cluster Management   Auto-config   Self-Healing   Auto-Scaling   One-click-deployment www.scalarium.com 3
  • 4. Database Requirements High Availability Easy Replication Clustering Robustness Short Recovery Time 4
  • 5. 5
  • 6. CouchDB Build for the Web Scales Replication built-in Embracing offline Flexible schema – document DB 6
  • 7. ”CouchDB is built of the Web“ Jacob Kaplan-Moss 7
  • 8. Web Technologies HTTP the access protocol JavaScript the query language JSON the storage format 8
  • 9. JSON Document { "_id": "BCCD12CBB", "_rev": "1-AB764C", "type": "person", "name": "Darth Vader", "age": 63, "headware": ["Helmet", "Sombrero"], "dark_side": true, "weapons": { "right_arm": "light_saber", "left_arm": null } } 9
  • 10. JSON Document { "_id": "BCCD12CBB", "_rev": "1-AB764C", "type": "person", "name": "Darth Vader", "age": 63, "headware": ["Helmet", "Sombrero"], "dark_side": true, "weapons": { "right_arm": "light_saber", "left_arm": null } } 10
  • 11. JSON Document { "_id": "BCCD12CBB", "_rev": "1-AB764C", "type": "person", "name": "Darth Vader", "age": 63, "headware": ["Helmet", "Sombrero"], "dark_side": true, "weapons": { "right_arm": "light_saber", "left_arm": null } } 11
  • 12. No Tables or Namespaces 12
  • 13. No Tables or Namespaces 13
  • 14. Manual Namespacing { "_id": "BCCD12CBB", "_rev": "1-AB764C", "type": "person", "name": "Darth Vader", "age": 63, "headware": ["Helmet", "Sombrero"], "dark_side": true, "weapons": { "right_arm": "light_saber", "left_arm": null } } 14
  • 15. Interacting with CouchDB JSON HTTP Client PUT /dbname/ID 15
  • 16. Interacting with CouchDB GET /dbname/ID HTTP Client JSON 16
  • 17. Interacting with CouchDB DELETE /dbname/ID HTTP Client 17
  • 18. Views 18
  • 19. Design Document { "id": "_design/hats”, "_rev": "431212AB4”, "language": "javascript”, "views": { "all": { "map": "function(doc){ .... }”, "reduce": "function(doc){ .... }” }, "by_manufacturer": { "map": "function(doc){ .... }”, "reduce": "function(doc){ .... }” } } } 19
  • 20. Design Document { Document ID "id": "_design/hats”, – "_rev": "431212AB4”, prefixed by “_design/” "language": "javascript”, "views": { "all": { "map": "function(doc){ .... }”, "reduce": "function(doc){ .... }” }, "by_manufacturer": { "map": "function(doc){ .... }”, "reduce": "function(doc){ .... }” } } } 20
  • 21. Design Document { "id": "_design/hats”, "_rev": "431212AB4”, "language": "javascript”, "views": { "all": { Hash of Views "map": "function(doc){ .... }”, "reduce": "function(doc){ .... }” }, "by_manufacturer": { "map": "function(doc){ .... }”, "reduce": "function(doc){ .... }” } } } 21
  • 22. Design Document { "id": "_design/hats”, "_rev": "431212AB4”, "language": "javascript”, "views": { "all": { Hash of Views "map": "function(doc){ .... }”, Every view has map & "reduce": "function(doc){ .... }” reduce function }, "by_manufacturer": { "map": "function(doc){ .... }”, "reduce": "function(doc){ .... }” } } } 22
  • 23. Map function(doc) { if (doc.headware) { for (var hat in doc.headware) { emit(hat, 1); } } } 23
  • 24. Map Passed every document in the DB function(doc) { if (doc.headware) { for (var hat in doc.headware) { emit(hat, 1); } } } 24
  • 25. Map function(doc) { if (doc.headware) { Inspects for (var hat in doc.headware) { & Decides emit(hat, 1); } } } 25
  • 26. Map function(doc) { if (doc.headware) { for (var hat in doc.headware) { emit(hat, 1); } } Emits result } for index 26
  • 27. Reduce function(keys, values, rereduce) { return sum(values); } 27
  • 28. Reduce Passed map result (or partial reduce result) function(keys, values, rereduce) { return sum(values); } 28
  • 29. Reduce function(keys, values, rereduce) { return sum(values); } Aggregates (count, sum, average, …) 29
  • 30. Example Map Result Map functions are similar to SQL indices ID KEY VALUE 51ABFA211 Cap 1 ABC123456 Cappy 1 BCCD12CBB Helmet 1 BCCD12CBB Sombrero 1 Sorted by the key Key can also be an array Value can be complex JSON and/or reference to other document 30
  • 31. Query a view GET /dbname/_design/hats/_view/all HTTP Client {"total_rows":348,"offset":0,"rows”:[ {"id":"A","key":"A","value":1}, {"id":"B","key":"B","value":1}, ]} 31
  • 32. Query a view GET /dbname/_design/hats/_view/all? include_docs=true HTTP Client 32
  • 33. View Query Filter by   key=ABC123   startkey=123 & endkey=9   limit=100   descending=true   group=true   reduce=true   Include_docs=true 33
  • 35. Using Couch from PHP Several options available   PHPillow: http://arbitracker.org/phpillow.html (LGPL 3)   PHP Object_Freezer: https://github.com/sebastianbergmann/php-object-freezer/tree (BSD)   PHP On Couch: http://github.com/dready92/PHP-on-Couch/tree/master (GPLv2 or v3)   PHP CouchDB Extension: http://www.topdog.za.net/php_couchdb_extension (PHP License 3.0)   Sag for CouchDB: http://www.saggingcouch.com/ (Apache License 2.0) 35
  • 36. 36
  • 37. 37
  • 38. 38
  • 39. 39
  • 40. SimplyStored CouchDB convenience Layer for Ruby   Models & Associations   Validations   Callbacks BSD-licensed on   Dynamic finder http://github.com/peritor/simply_stored   S3 attachments On top of CouchPotato, CouchRest & RestClient   Paranoid delete   ActiveModel compliant 40
  • 41. Many more Or just build your own using HTTP! 41
  • 42. Database Requirements High Availability Easy Replication Clustering Robustness Short Recovery Time 42
  • 43. Replication B-Tree XXXXX Photo by Mathias Meyer 43
  • 44. B-Tree Append only Concurrency (MVCC) Crash resistant Hot backups Compaction 44
  • 46. CouchDB Replication POST /_replicate POST /_replicate Eventually consistent & conflict resolution 46
  • 47. Load Balancing Replication HTTP Client HTTP Load Balancer 47
  • 48. Caching HTTP Client HTTP Cache Varnish Apache … 48
  • 50. BigCouch   Clustered CouchDB: Many CouchDBs appear as one   Modeled after Amazon Dynamo   Scalability like Cassandra or Riak   github.com/cloudant/bigcouch 50
  • 51. Q – No. of partitions BigCouch N – No. of replicas R – Read quorum W – Write quorum 51
  • 52. Various CouchApps Validations Filtered replication Changes feed List functions Futon Geo Fulltext-Search with embedded Lucene Different experimental View-Server 52
  • 53. Q&A Peritor GmbH Blücherstr. 22, Hof III Aufgang 6 10961 Berlin Tel.: +49 (0)30 69 20 09 84 0 Fax: +49 (0)30 69 20 09 84 9 Internet: www.peritor.com E-Mail: info@peritor.com © Peritor GmbH - Alle Rechte vorbehalten