SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
06/06/11   1
ABOUT ME
Rocky Jaiswal
Daytime job – Software Architect at McKinsey & Co
Programmer / Agilist at heart
Have been programming for almost 9 years, plan to do it for a long
loooong time
I     Java/Ruby/JRuby/jQuery and anything to do with web
application development
Want to build good looking, scalable and performing websites that
help people
Blog – www.rockyj.in
Twitter – www.twitter.com/whatsuprocky
                                                                     2
Why we need the cloud
I am a developer. Don’t want the hassle to maintain
infrastructure.


We are a small organization. We want cheap and flexible
infrastructure.


I / we want to scale easily. Be it scale up or scale down.


*Choice of technology also determines how easily you can
scale. e.g. Use of NoSQL instead of a RDBMS


                                                              3
A WORKING EXAMPLE




http://biblefind.in
                      4
HELLO COUCHDB
Apache CouchDB is a document-oriented database that
can be queried and indexed in a MapReduce fashion
using JavaScript.

CouchDB also offers incremental replication with bi-
directional conflict detection and resolution.

CouchDB provides a RESTful JSON API than can be
accessed from any environment that allows HTTP
requests.

+ It offers an easy introduction to the world of NoSQL

                                                         5
HELLO COUCHDB – DOCUMENT ORIENTED

A different way to model your data.

Data stored in documents

Think of it as a de-normalized
table row




                                      6
HELLO COUCHDB -
MAPREDUCE
MapReduce – Divide and Rule for programmers

How would you count the occurrences of each
word in a book given a group of helpers




                                              7
HELLO COUCHDB –
JSON/HTTP
When we talk of databases we talk of drivers 

CouchDB’s protocol is HTTP

The data exchange + storage language is JSON

{
        “Subject” : “I like JSON”,
        “Author” : “Rocky”,
        “Tags” : [
                  “Web”, “Programming”, “Data Exchange”
        ]
}

And the queries are written in JavaScript

                                                          8
PARSING THE BIBLE AND STORING IT IN
COUCHDB




                                      9
CREATING VIEWS IN
COUCHDB
Views are like queries. Hmmm… more like Stored Procedures

Views are expressed as Map + Reduce functions written in JavaScript

For example my view to query all the verses –

{
    "lookup": {
      "map": "function(doc){
                      if (doc.book && doc.chapter && doc.verse && doc.text){
                                key = [doc.book, doc.chapter, doc.verse];
                                emit(key, doc.text);
                      }
            }"
    }
}

CouchDB runs the function for every document in DB and stores results in a B-Tree.
                                                                                 10
THE COUCHREST GEM

CouchRest lightly wraps CouchDB's HTTP API,
managing JSON serialization, and remembering the
URI-paths to CouchDB's API endpoints so you don't
have to.

@db = CouchRest.database!
("http://127.0.0.1:5984/the_bible")

@db.save_doc(
{:key => 'value', 'another key' => 'another value'}
)
                                                      11
THE RAILS APPLICATION

So our back-end is set

We only need a front-end now

Nothing much needs to be done

      1 Controller

      1 View

      Some jQuery for autocomplete
                                     12
REGEX NIGHTMARES

Matthew 1 – One whole chapter

Mark 2:3 – One verse

Psalms 23:1-4 – A set of verses

For God so loved the world – Free Text




                                         13
LUCENE INTEGRATION
Couchdb-lucene (https://github.com/rnewson/couchdb-lucene)

Java project

CouchDB View –

@db.save_doc({
  "_id" => "_design/lucene",
  :fulltext => {
    :by_text => {
       :index => "function(doc) { var ret=new Document(); ret.add(doc.text);
                    return ret }"
    }
  }
})

                                                                               14
LUCENE INTEGRATION
CONTD..
CouchDB config -

[external]
fti=python /home/rocky/Apps/couchdb-lucene-0.7-
SNAPSHOT/tools/couchdb-external-hook.py

[httpd_db_handlers]
_fti = {couch_httpd_external, handle_external_req,
<<"fti">>}


                                                     15
USING HEROKU
Rails application hosting provider
Free for 1 “Dyno” + 1 Shared database




                                        16
USING HEROKU CONTD..




                       17
USING SLICEHOST




                  18
PUTTING IT OUT IN THE BIG BAD
WORLD
Buy a domain name from http://www.godaddy.com
Or a domain provider of your choice



In Heroku add the domain name

Add the Zerigo add-on in Heroku

In godaddy’s admin console point your nameservers to
Zerigo’s name servers

Wait …
                                                  19
SCALING

Heroku makes scaling dead easy




                                 20
SCALING

Heroku makes scaling dead easy (if we were using SQL)




                                                   21
SCALING

In NoSQL world, replication is a first class citizen




 POST /_replicate {
 “source”:”a”, “target”:”b”, “continuous”:”true”
 }
                                                       22
SCALING (HOT BACKUP)




                       23
SCALING WITH A DUMB PROXY




                            24
SCALING WITH COUCHDB LOUNGE

Have a look at CouchDB Lounge

It consists of –
       a dumb proxy that is a module for nginx
       a smart proxy that distributes work

All in all, make a cluster –
        Have continuous replication
        Use Lounge to distribute load


                                                 25
WHEN NOT TO USE COUCHDB

When the number of writes far exceed the number of
reads (plus the data volume is very high)
      - This would create a bottleneck for replication
      - And you may encounter more conflicts


When you need ad-hoc queries
     - You cannot use the power of views in this case


Use CouchDB’s brother MongoDB in this case.
                                                         26
THANKS




         27

Más contenido relacionado

La actualidad más candente

MS Cloud Day - Building web applications with Azure storage
MS Cloud Day - Building web applications with Azure storageMS Cloud Day - Building web applications with Azure storage
MS Cloud Day - Building web applications with Azure storage
Spiffy
 

La actualidad más candente (20)

Windows Azure Drive
Windows Azure DriveWindows Azure Drive
Windows Azure Drive
 
Microsoft Azure Media Services
Microsoft Azure Media ServicesMicrosoft Azure Media Services
Microsoft Azure Media Services
 
Storage as a Service with Gluster
Storage as a Service with GlusterStorage as a Service with Gluster
Storage as a Service with Gluster
 
MS Cloud Day - Building web applications with Azure storage
MS Cloud Day - Building web applications with Azure storageMS Cloud Day - Building web applications with Azure storage
MS Cloud Day - Building web applications with Azure storage
 
Gdeploy 2.0
Gdeploy 2.0Gdeploy 2.0
Gdeploy 2.0
 
Introduction to mongo db
Introduction to mongo dbIntroduction to mongo db
Introduction to mongo db
 
HBaseCon 2012 | Content Addressable Storages for Fun and Profit - Berk Demir,...
HBaseCon 2012 | Content Addressable Storages for Fun and Profit - Berk Demir,...HBaseCon 2012 | Content Addressable Storages for Fun and Profit - Berk Demir,...
HBaseCon 2012 | Content Addressable Storages for Fun and Profit - Berk Demir,...
 
CBDW2014 - NoSQL Development With Couchbase and ColdFusion (CFML)
CBDW2014 - NoSQL Development With Couchbase and ColdFusion (CFML)CBDW2014 - NoSQL Development With Couchbase and ColdFusion (CFML)
CBDW2014 - NoSQL Development With Couchbase and ColdFusion (CFML)
 
Postgres connections at scale
Postgres connections at scalePostgres connections at scale
Postgres connections at scale
 
Webpack
WebpackWebpack
Webpack
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & Introduction
 
DMS (Database Migration Service) - Mydbops Team
DMS  (Database Migration Service) - Mydbops TeamDMS  (Database Migration Service) - Mydbops Team
DMS (Database Migration Service) - Mydbops Team
 
Qemu gluster fs
Qemu gluster fsQemu gluster fs
Qemu gluster fs
 
Dumitru Enache - Bacula
Dumitru Enache - BaculaDumitru Enache - Bacula
Dumitru Enache - Bacula
 
HBaseCon2017 Efficient and portable data processing with Apache Beam and HBase
HBaseCon2017 Efficient and portable data processing with Apache Beam and HBaseHBaseCon2017 Efficient and portable data processing with Apache Beam and HBase
HBaseCon2017 Efficient and portable data processing with Apache Beam and HBase
 
hbaseconasia2017: HBase on Beam
hbaseconasia2017: HBase on Beamhbaseconasia2017: HBase on Beam
hbaseconasia2017: HBase on Beam
 
Mashing the data
Mashing the dataMashing the data
Mashing the data
 
State of the_gluster_-_lceu
State of the_gluster_-_lceuState of the_gluster_-_lceu
State of the_gluster_-_lceu
 
MongoDB WiredTiger Internals
MongoDB WiredTiger InternalsMongoDB WiredTiger Internals
MongoDB WiredTiger Internals
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 

Similar a Putting rails and couch db on the cloud - Indicthreads cloud computing conference 2011

Hadoop Spark - Reuniao SouJava 12/04/2014
Hadoop Spark - Reuniao SouJava 12/04/2014Hadoop Spark - Reuniao SouJava 12/04/2014
Hadoop Spark - Reuniao SouJava 12/04/2014
soujavajug
 
CouchDB: A NoSQL database
CouchDB: A NoSQL databaseCouchDB: A NoSQL database
CouchDB: A NoSQL database
Rubyc Slides
 
NoSQL: Why, When, and How
NoSQL: Why, When, and HowNoSQL: Why, When, and How
NoSQL: Why, When, and How
BigBlueHat
 
jclouds High Level Overview by Adrian Cole
jclouds High Level Overview by Adrian Colejclouds High Level Overview by Adrian Cole
jclouds High Level Overview by Adrian Cole
Everett Toews
 

Similar a Putting rails and couch db on the cloud - Indicthreads cloud computing conference 2011 (20)

Intro Couchdb
Intro CouchdbIntro Couchdb
Intro Couchdb
 
Manuel Hurtado. Couchbase paradigma4oct
Manuel Hurtado. Couchbase paradigma4octManuel Hurtado. Couchbase paradigma4oct
Manuel Hurtado. Couchbase paradigma4oct
 
Shipping Applications to Production in Containers with Docker
Shipping Applications to Production in Containers with DockerShipping Applications to Production in Containers with Docker
Shipping Applications to Production in Containers with Docker
 
JS App Architecture
JS App ArchitectureJS App Architecture
JS App Architecture
 
RESTful OSGi middleware for NoSQL databases with Docker
RESTful OSGi middleware for NoSQL databases with DockerRESTful OSGi middleware for NoSQL databases with Docker
RESTful OSGi middleware for NoSQL databases with Docker
 
ArangoDB
ArangoDBArangoDB
ArangoDB
 
Hadoop Spark - Reuniao SouJava 12/04/2014
Hadoop Spark - Reuniao SouJava 12/04/2014Hadoop Spark - Reuniao SouJava 12/04/2014
Hadoop Spark - Reuniao SouJava 12/04/2014
 
Couch db
Couch dbCouch db
Couch db
 
Data Analysis with Hadoop and Hive, ChicagoDB 2/21/2011
Data Analysis with Hadoop and Hive, ChicagoDB 2/21/2011Data Analysis with Hadoop and Hive, ChicagoDB 2/21/2011
Data Analysis with Hadoop and Hive, ChicagoDB 2/21/2011
 
Couch db
Couch dbCouch db
Couch db
 
CouchDB
CouchDBCouchDB
CouchDB
 
CouchDB: A NoSQL database
CouchDB: A NoSQL databaseCouchDB: A NoSQL database
CouchDB: A NoSQL database
 
NoSQL: Why, When, and How
NoSQL: Why, When, and HowNoSQL: Why, When, and How
NoSQL: Why, When, and How
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Accelerate your development with Docker
Accelerate your development with DockerAccelerate your development with Docker
Accelerate your development with Docker
 
Accelerate your software development with Docker
Accelerate your software development with DockerAccelerate your software development with Docker
Accelerate your software development with Docker
 
Introduction to Sqoop Aaron Kimball Cloudera Hadoop User Group UK
Introduction to Sqoop Aaron Kimball Cloudera Hadoop User Group UKIntroduction to Sqoop Aaron Kimball Cloudera Hadoop User Group UK
Introduction to Sqoop Aaron Kimball Cloudera Hadoop User Group UK
 
jclouds High Level Overview by Adrian Cole
jclouds High Level Overview by Adrian Colejclouds High Level Overview by Adrian Cole
jclouds High Level Overview by Adrian Cole
 
DevEx | there’s no place like k3s
DevEx | there’s no place like k3sDevEx | there’s no place like k3s
DevEx | there’s no place like k3s
 
London HUG 8/3 - Nomad
London HUG 8/3 - NomadLondon HUG 8/3 - Nomad
London HUG 8/3 - Nomad
 

Más de IndicThreads

Scrap Your MapReduce - Apache Spark
 Scrap Your MapReduce - Apache Spark Scrap Your MapReduce - Apache Spark
Scrap Your MapReduce - Apache Spark
IndicThreads
 
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
 Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
IndicThreads
 
Unraveling OpenStack Clouds
 Unraveling OpenStack Clouds Unraveling OpenStack Clouds
Unraveling OpenStack Clouds
IndicThreads
 

Más de IndicThreads (20)

Http2 is here! And why the web needs it
Http2 is here! And why the web needs itHttp2 is here! And why the web needs it
Http2 is here! And why the web needs it
 
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
Understanding Bitcoin (Blockchain) and its Potential for Disruptive ApplicationsUnderstanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
 
Go Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang wayGo Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang way
 
Building Resilient Microservices
Building Resilient Microservices Building Resilient Microservices
Building Resilient Microservices
 
App using golang indicthreads
App using golang  indicthreadsApp using golang  indicthreads
App using golang indicthreads
 
Building on quicksand microservices indicthreads
Building on quicksand microservices  indicthreadsBuilding on quicksand microservices  indicthreads
Building on quicksand microservices indicthreads
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingHow to Think in RxJava Before Reacting
How to Think in RxJava Before Reacting
 
Iot secure connected devices indicthreads
Iot secure connected devices indicthreadsIot secure connected devices indicthreads
Iot secure connected devices indicthreads
 
Real world IoT for enterprises
Real world IoT for enterprisesReal world IoT for enterprises
Real world IoT for enterprises
 
IoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreadsIoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreads
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present Future
 
Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams
 
Building & scaling a live streaming mobile platform - Gr8 road to fame
Building & scaling a live streaming mobile platform - Gr8 road to fameBuilding & scaling a live streaming mobile platform - Gr8 road to fame
Building & scaling a live streaming mobile platform - Gr8 road to fame
 
Internet of things architecture perspective - IndicThreads Conference
Internet of things architecture perspective - IndicThreads ConferenceInternet of things architecture perspective - IndicThreads Conference
Internet of things architecture perspective - IndicThreads Conference
 
Cars and Computers: Building a Java Carputer
 Cars and Computers: Building a Java Carputer Cars and Computers: Building a Java Carputer
Cars and Computers: Building a Java Carputer
 
Scrap Your MapReduce - Apache Spark
 Scrap Your MapReduce - Apache Spark Scrap Your MapReduce - Apache Spark
Scrap Your MapReduce - Apache Spark
 
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
 Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
 
Speed up your build pipeline for faster feedback
Speed up your build pipeline for faster feedbackSpeed up your build pipeline for faster feedback
Speed up your build pipeline for faster feedback
 
Unraveling OpenStack Clouds
 Unraveling OpenStack Clouds Unraveling OpenStack Clouds
Unraveling OpenStack Clouds
 
Digital Transformation of the Enterprise. What IT leaders need to know!
Digital Transformation of the Enterprise. What IT  leaders need to know!Digital Transformation of the Enterprise. What IT  leaders need to know!
Digital Transformation of the Enterprise. What IT leaders need to know!
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Putting rails and couch db on the cloud - Indicthreads cloud computing conference 2011

  • 2. ABOUT ME Rocky Jaiswal Daytime job – Software Architect at McKinsey & Co Programmer / Agilist at heart Have been programming for almost 9 years, plan to do it for a long loooong time I Java/Ruby/JRuby/jQuery and anything to do with web application development Want to build good looking, scalable and performing websites that help people Blog – www.rockyj.in Twitter – www.twitter.com/whatsuprocky 2
  • 3. Why we need the cloud I am a developer. Don’t want the hassle to maintain infrastructure. We are a small organization. We want cheap and flexible infrastructure. I / we want to scale easily. Be it scale up or scale down. *Choice of technology also determines how easily you can scale. e.g. Use of NoSQL instead of a RDBMS 3
  • 5. HELLO COUCHDB Apache CouchDB is a document-oriented database that can be queried and indexed in a MapReduce fashion using JavaScript. CouchDB also offers incremental replication with bi- directional conflict detection and resolution. CouchDB provides a RESTful JSON API than can be accessed from any environment that allows HTTP requests. + It offers an easy introduction to the world of NoSQL 5
  • 6. HELLO COUCHDB – DOCUMENT ORIENTED A different way to model your data. Data stored in documents Think of it as a de-normalized table row 6
  • 7. HELLO COUCHDB - MAPREDUCE MapReduce – Divide and Rule for programmers How would you count the occurrences of each word in a book given a group of helpers 7
  • 8. HELLO COUCHDB – JSON/HTTP When we talk of databases we talk of drivers  CouchDB’s protocol is HTTP The data exchange + storage language is JSON { “Subject” : “I like JSON”, “Author” : “Rocky”, “Tags” : [ “Web”, “Programming”, “Data Exchange” ] } And the queries are written in JavaScript 8
  • 9. PARSING THE BIBLE AND STORING IT IN COUCHDB 9
  • 10. CREATING VIEWS IN COUCHDB Views are like queries. Hmmm… more like Stored Procedures Views are expressed as Map + Reduce functions written in JavaScript For example my view to query all the verses – { "lookup": { "map": "function(doc){ if (doc.book && doc.chapter && doc.verse && doc.text){ key = [doc.book, doc.chapter, doc.verse]; emit(key, doc.text); } }" } } CouchDB runs the function for every document in DB and stores results in a B-Tree. 10
  • 11. THE COUCHREST GEM CouchRest lightly wraps CouchDB's HTTP API, managing JSON serialization, and remembering the URI-paths to CouchDB's API endpoints so you don't have to. @db = CouchRest.database! ("http://127.0.0.1:5984/the_bible") @db.save_doc( {:key => 'value', 'another key' => 'another value'} ) 11
  • 12. THE RAILS APPLICATION So our back-end is set We only need a front-end now Nothing much needs to be done 1 Controller 1 View Some jQuery for autocomplete 12
  • 13. REGEX NIGHTMARES Matthew 1 – One whole chapter Mark 2:3 – One verse Psalms 23:1-4 – A set of verses For God so loved the world – Free Text 13
  • 14. LUCENE INTEGRATION Couchdb-lucene (https://github.com/rnewson/couchdb-lucene) Java project CouchDB View – @db.save_doc({ "_id" => "_design/lucene", :fulltext => { :by_text => { :index => "function(doc) { var ret=new Document(); ret.add(doc.text); return ret }" } } }) 14
  • 15. LUCENE INTEGRATION CONTD.. CouchDB config - [external] fti=python /home/rocky/Apps/couchdb-lucene-0.7- SNAPSHOT/tools/couchdb-external-hook.py [httpd_db_handlers] _fti = {couch_httpd_external, handle_external_req, <<"fti">>} 15
  • 16. USING HEROKU Rails application hosting provider Free for 1 “Dyno” + 1 Shared database 16
  • 19. PUTTING IT OUT IN THE BIG BAD WORLD Buy a domain name from http://www.godaddy.com Or a domain provider of your choice In Heroku add the domain name Add the Zerigo add-on in Heroku In godaddy’s admin console point your nameservers to Zerigo’s name servers Wait … 19
  • 21. SCALING Heroku makes scaling dead easy (if we were using SQL) 21
  • 22. SCALING In NoSQL world, replication is a first class citizen POST /_replicate { “source”:”a”, “target”:”b”, “continuous”:”true” } 22
  • 24. SCALING WITH A DUMB PROXY 24
  • 25. SCALING WITH COUCHDB LOUNGE Have a look at CouchDB Lounge It consists of – a dumb proxy that is a module for nginx a smart proxy that distributes work All in all, make a cluster – Have continuous replication Use Lounge to distribute load 25
  • 26. WHEN NOT TO USE COUCHDB When the number of writes far exceed the number of reads (plus the data volume is very high) - This would create a bottleneck for replication - And you may encounter more conflicts When you need ad-hoc queries - You cannot use the power of views in this case Use CouchDB’s brother MongoDB in this case. 26
  • 27. THANKS 27