SlideShare a Scribd company logo
1 of 24
Download to read offline
#geekcampsg 2009
                            CouchApps - Applications built on CouchDB


                                          Arun Thampi
                                           @iamclovin
                                          http://mclov.in



Saturday, August 22, 2009
About myself

                  •         Ruby Developer + Dabbler at Wego.com

                      •      The kick-ass travel meta-search engine

                  •         Work with great set of people


                                    @winstonyw         @reds          @mongeslani
              @chuyeow                                                              @jefflimar
                                    @phungleson     @ijuzwannatwit    @garytheis


Saturday, August 22, 2009
CouchDB FTW
                  •         Schema-less Key-Value based   •   MVCC (No Locks)
                            document store
                                                          •   Replication
                  •         Erlang
                                                          •   Scaling out of the box (HAProxy/
                  •         Speaks HTTP / REST                Nginx)

                  •         Map Reduce                    •   Full Text Search (Lucene/Sphinx)

                  •         JSON                          •   Attachments (binary files)

                  •         Social Media                  •   Web Interface (Futon)

Saturday, August 22, 2009
Profit

Saturday, August 22, 2009
CouchDB - Built for the Web
                            {
                                “_id” : “abc”,
                                “_rev” : “abc123def”,
                                “text” : “Hello World”,
                                “screen_name” : “mclovin”,
                                “timestamp” : 123232,
                                “type” : “thread”,
                                “replies”: [ “reply 1”, “reply 2”, “reply 3”]
                            }


Saturday, August 22, 2009
CouchDB - Built for the web
                              Inserting a document            HTTP PUT

                              Retrieving a document          HTTP GET

                              Deleting a document           HTTP DELETE

                              Updating a document            HTTP POST

                                     Scaling          Replication + load balancing

                                    Querying                       ?

Saturday, August 22, 2009
Saturday, August 22, 2009
Map Reduce with Javascript Views
                                     (No I wasn’t making that up)


                  Document 1                         [Key 1, Value 1]



                  Document 2   Map Function          [Key 2, Value 2]   Reduce Function




                                                     [Key k,Value k]
                  Document n                                               Value X




Saturday, August 22, 2009
Example Map Reduce
                                       Map Function



                            function(doc) {
                              if(doc.type == “customer”) {
                                emit(doc.first_name, 1);
                              }
                            }




Saturday, August 22, 2009
Example Map Reduce (contd)
                                         Reduce Function




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




Saturday, August 22, 2009
Example Map Reduce (contd)
             {
                   ..
                   {
                            “key”: “Seth”,
                            “value”: 1
                   },
                                               reduce([“Seth”, “Fogell”], [1, 1])
                   {
                            “key”: “Fogell”,
                            “value”: 1
                   }
                   ..
             }

Saturday, August 22, 2009
CouchApps


                  •         HTTP / HTML / Javascript is the language of the web

                  •         Coincidentally, that’s what CouchDB speaks too

                  •         Why not have CouchDB apps serve apps?




Saturday, August 22, 2009
CouchApps - Why?

                  •         Barriers to entry to develop powerful data-backed applications is
                            lowered

                  •         Replication enables load-balancing + scaling

                  •         No Impedance Mismatch - Data is Javascript, your views are in
                            Javascript, your HTML pages are rendered in Javascript



Saturday, August 22, 2009
CouchApps
        •       Available at http://github.com/
                couchapp/couchapp

        •       couchapp generate icanhazthread

        •       couchapp push icanhazthread http://
                127.0.0.1:5984/icanhazthread




Saturday, August 22, 2009
CouchApps - List & Show Functions
                                                                            Schema-less
                                                                 Model
            •      A view is queried and the results are                       JSON

                   passed to a list function

            •      List Function then renders the results
                                                                            Map/Reduce
                   of your view in whatever format you         Controller
                                                                               View
                   please: HTML, JSON, XML, RSS, etc

            •      In a twisted way, its like a controller +
                   view concept in an MVC framework
                                                                 View        List/Show



Saturday, August 22, 2009
Introducing i.canhazthread.com

                  •         Inspired (in fact, cloned) from a.tinythread.com by Joshua Schacter

                  •         Backend powered by a CouchApp (http://github.com/arunthampi/
                            icanhazthread)

                  •         Uses Rails to do Twitter authentication + HTML rendering




Saturday, August 22, 2009
icanhazthread.com

                                             nginx


                                                     CouchDB API [RSS, Realtime]


                            Rails Mongrels            CouchDB




Saturday, August 22, 2009
Document Structure
                            Thread                       Reply

      {                                   {
             “_id” : “abc”,                   “_id” : “def”,
             “_rev” : “abc123def”,            “_rev” : “234abcdef”,
             “text” : “Hello World”,          “text” : “oh hai”,
             “screen_name” : “mclovin”,       “screen_name” : “snehamenon”,
             “timestamp” : 123232,            “timestamp” : 1232310,
             “type” : “thread”                “type” : “reply”,
      }                                       “thread_id” : “abc”
                                          }

Saturday, August 22, 2009
Interesting Map/Reduce problem
                                 (at least for me)

                                             •   Interesting because replies are not
                                                 contained within a thread

                                             •   Also, because threads on the
                                                 homepage need to be sorted
                                                 according to timestamp (newest
                                                 ones first)

                                             •   Views need to be commutative &
                                                 associative


Saturday, August 22, 2009
Show me the code
                                          Map Function (yawn)

                        function(doc) {
                          if(doc.type == ‘thread’) {
                            emit([doc.id, doc.time_created], doc);
                          } else if(doc.type == ‘reply’) {
                            emit([doc.thread_id, doc.time_created], doc);
                          }
                        }




Saturday, August 22, 2009
Show me the code                                 Thread        Reply         Result


                            Reduce Function
                                                                               Sorting?


                [K1, V1]         [K2,V2]                                [K1, Summary for Thread 1]


                                                                           num_replies: 2
              [K1, RV1]
                                              group_level =1            [K2, Summary for Thread 2]


              [K1, RV2]                                                    num_replies: 0

Saturday, August 22, 2009
Future Directions


                  •         Make icanhazthread real-time (Utilize the _changes API in CouchDB)

                  •         RSS Feeds (Dead simple with the CouchApp list)

                  •         etc etc




Saturday, August 22, 2009
Resources
                  •         CouchDB Wiki: http://wiki.couchdb.org

                  •         CouchDB Mailing lists (user + dev)

                  •         Blogs: Chris Anderson, Harish Mallipeddi, Jan Lenhardt

                  •         CouchDB Futon Test Suite (http://127.0.0.1:5984/_utils/
                            couch_tests.html)

                  •         Other CouchApps: Toast, Chris Anderson’s blog


Saturday, August 22, 2009
Thank you


                             Q &A



Saturday, August 22, 2009

More Related Content

Similar to GeekCamp SG 2009 - CouchApps with CouchDB

Putting rails and couch db on the cloud - Indicthreads cloud computing confe...
Putting rails and couch db on the cloud -  Indicthreads cloud computing confe...Putting rails and couch db on the cloud -  Indicthreads cloud computing confe...
Putting rails and couch db on the cloud - Indicthreads cloud computing confe...IndicThreads
 
ソーシャルアプリでの Amazon Elastic MapReduce 活用事例
ソーシャルアプリでの Amazon Elastic MapReduce 活用事例ソーシャルアプリでの Amazon Elastic MapReduce 活用事例
ソーシャルアプリでの Amazon Elastic MapReduce 活用事例Takahiro Kamatani
 
Couchdbkit djangocong-20100425
Couchdbkit djangocong-20100425Couchdbkit djangocong-20100425
Couchdbkit djangocong-20100425guest4f2eea
 
JavaScript Library Overview (Ajax Exp West 2007)
JavaScript Library Overview (Ajax Exp West 2007)JavaScript Library Overview (Ajax Exp West 2007)
JavaScript Library Overview (Ajax Exp West 2007)jeresig
 
Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android
Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on AndroidMeetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android
Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Androidgdgoslo
 
Ruboto at GDG Oslo 2013
Ruboto at GDG Oslo 2013Ruboto at GDG Oslo 2013
Ruboto at GDG Oslo 2013Uwe Kubosch
 
Social Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDBSocial Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDBTakahiro Inoue
 
Geo Package and OWS Context at FOSS4G PDX
Geo Package and OWS Context at FOSS4G PDXGeo Package and OWS Context at FOSS4G PDX
Geo Package and OWS Context at FOSS4G PDXLuis Bermudez
 
Cloud is such stuff as dreams are made on
Cloud is such stuff as dreams are made onCloud is such stuff as dreams are made on
Cloud is such stuff as dreams are made onPatrick Chanezon
 
Scaling webappswithrabbitmq
Scaling webappswithrabbitmqScaling webappswithrabbitmq
Scaling webappswithrabbitmqAlvaro Videla
 
CouchDB and Rails on the Cloud
CouchDB and Rails on the CloudCouchDB and Rails on the Cloud
CouchDB and Rails on the Cloudrockyjaiswal
 
Geoindexing with MongoDB
Geoindexing with MongoDBGeoindexing with MongoDB
Geoindexing with MongoDBleafnode
 
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGuillaume Laforge
 

Similar to GeekCamp SG 2009 - CouchApps with CouchDB (20)

Putting rails and couch db on the cloud - Indicthreads cloud computing confe...
Putting rails and couch db on the cloud -  Indicthreads cloud computing confe...Putting rails and couch db on the cloud -  Indicthreads cloud computing confe...
Putting rails and couch db on the cloud - Indicthreads cloud computing confe...
 
dojo.things()
dojo.things()dojo.things()
dojo.things()
 
ソーシャルアプリでの Amazon Elastic MapReduce 活用事例
ソーシャルアプリでの Amazon Elastic MapReduce 活用事例ソーシャルアプリでの Amazon Elastic MapReduce 活用事例
ソーシャルアプリでの Amazon Elastic MapReduce 活用事例
 
Couchdbkit djangocong-20100425
Couchdbkit djangocong-20100425Couchdbkit djangocong-20100425
Couchdbkit djangocong-20100425
 
Couchdbkit & Dango
Couchdbkit & DangoCouchdbkit & Dango
Couchdbkit & Dango
 
MongoDB and hadoop
MongoDB and hadoopMongoDB and hadoop
MongoDB and hadoop
 
No sql Database
No sql DatabaseNo sql Database
No sql Database
 
JavaScript Library Overview (Ajax Exp West 2007)
JavaScript Library Overview (Ajax Exp West 2007)JavaScript Library Overview (Ajax Exp West 2007)
JavaScript Library Overview (Ajax Exp West 2007)
 
Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android
Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on AndroidMeetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android
Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android
 
Ruboto at GDG Oslo 2013
Ruboto at GDG Oslo 2013Ruboto at GDG Oslo 2013
Ruboto at GDG Oslo 2013
 
Aleact
AleactAleact
Aleact
 
Social Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDBSocial Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDB
 
Processing
ProcessingProcessing
Processing
 
Geo Package and OWS Context at FOSS4G PDX
Geo Package and OWS Context at FOSS4G PDXGeo Package and OWS Context at FOSS4G PDX
Geo Package and OWS Context at FOSS4G PDX
 
Cloud is such stuff as dreams are made on
Cloud is such stuff as dreams are made onCloud is such stuff as dreams are made on
Cloud is such stuff as dreams are made on
 
Scaling webappswithrabbitmq
Scaling webappswithrabbitmqScaling webappswithrabbitmq
Scaling webappswithrabbitmq
 
CouchDB and Rails on the Cloud
CouchDB and Rails on the CloudCouchDB and Rails on the Cloud
CouchDB and Rails on the Cloud
 
Geoindexing with MongoDB
Geoindexing with MongoDBGeoindexing with MongoDB
Geoindexing with MongoDB
 
Agi08 Jeremy Morley
Agi08 Jeremy MorleyAgi08 Jeremy Morley
Agi08 Jeremy Morley
 
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
 

Recently uploaded

[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneUiPathCommunity
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 

Recently uploaded (20)

[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyone
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 

GeekCamp SG 2009 - CouchApps with CouchDB

  • 1. #geekcampsg 2009 CouchApps - Applications built on CouchDB Arun Thampi @iamclovin http://mclov.in Saturday, August 22, 2009
  • 2. About myself • Ruby Developer + Dabbler at Wego.com • The kick-ass travel meta-search engine • Work with great set of people @winstonyw @reds @mongeslani @chuyeow @jefflimar @phungleson @ijuzwannatwit @garytheis Saturday, August 22, 2009
  • 3. CouchDB FTW • Schema-less Key-Value based • MVCC (No Locks) document store • Replication • Erlang • Scaling out of the box (HAProxy/ • Speaks HTTP / REST Nginx) • Map Reduce • Full Text Search (Lucene/Sphinx) • JSON • Attachments (binary files) • Social Media • Web Interface (Futon) Saturday, August 22, 2009
  • 5. CouchDB - Built for the Web { “_id” : “abc”, “_rev” : “abc123def”, “text” : “Hello World”, “screen_name” : “mclovin”, “timestamp” : 123232, “type” : “thread”, “replies”: [ “reply 1”, “reply 2”, “reply 3”] } Saturday, August 22, 2009
  • 6. CouchDB - Built for the web Inserting a document HTTP PUT Retrieving a document HTTP GET Deleting a document HTTP DELETE Updating a document HTTP POST Scaling Replication + load balancing Querying ? Saturday, August 22, 2009
  • 8. Map Reduce with Javascript Views (No I wasn’t making that up) Document 1 [Key 1, Value 1] Document 2 Map Function [Key 2, Value 2] Reduce Function [Key k,Value k] Document n Value X Saturday, August 22, 2009
  • 9. Example Map Reduce Map Function function(doc) { if(doc.type == “customer”) { emit(doc.first_name, 1); } } Saturday, August 22, 2009
  • 10. Example Map Reduce (contd) Reduce Function function(keys, values, re) { return sum(values); } Saturday, August 22, 2009
  • 11. Example Map Reduce (contd) { .. { “key”: “Seth”, “value”: 1 }, reduce([“Seth”, “Fogell”], [1, 1]) { “key”: “Fogell”, “value”: 1 } .. } Saturday, August 22, 2009
  • 12. CouchApps • HTTP / HTML / Javascript is the language of the web • Coincidentally, that’s what CouchDB speaks too • Why not have CouchDB apps serve apps? Saturday, August 22, 2009
  • 13. CouchApps - Why? • Barriers to entry to develop powerful data-backed applications is lowered • Replication enables load-balancing + scaling • No Impedance Mismatch - Data is Javascript, your views are in Javascript, your HTML pages are rendered in Javascript Saturday, August 22, 2009
  • 14. CouchApps • Available at http://github.com/ couchapp/couchapp • couchapp generate icanhazthread • couchapp push icanhazthread http:// 127.0.0.1:5984/icanhazthread Saturday, August 22, 2009
  • 15. CouchApps - List & Show Functions Schema-less Model • A view is queried and the results are JSON passed to a list function • List Function then renders the results Map/Reduce of your view in whatever format you Controller View please: HTML, JSON, XML, RSS, etc • In a twisted way, its like a controller + view concept in an MVC framework View List/Show Saturday, August 22, 2009
  • 16. Introducing i.canhazthread.com • Inspired (in fact, cloned) from a.tinythread.com by Joshua Schacter • Backend powered by a CouchApp (http://github.com/arunthampi/ icanhazthread) • Uses Rails to do Twitter authentication + HTML rendering Saturday, August 22, 2009
  • 17. icanhazthread.com nginx CouchDB API [RSS, Realtime] Rails Mongrels CouchDB Saturday, August 22, 2009
  • 18. Document Structure Thread Reply { { “_id” : “abc”, “_id” : “def”, “_rev” : “abc123def”, “_rev” : “234abcdef”, “text” : “Hello World”, “text” : “oh hai”, “screen_name” : “mclovin”, “screen_name” : “snehamenon”, “timestamp” : 123232, “timestamp” : 1232310, “type” : “thread” “type” : “reply”, } “thread_id” : “abc” } Saturday, August 22, 2009
  • 19. Interesting Map/Reduce problem (at least for me) • Interesting because replies are not contained within a thread • Also, because threads on the homepage need to be sorted according to timestamp (newest ones first) • Views need to be commutative & associative Saturday, August 22, 2009
  • 20. Show me the code Map Function (yawn) function(doc) { if(doc.type == ‘thread’) { emit([doc.id, doc.time_created], doc); } else if(doc.type == ‘reply’) { emit([doc.thread_id, doc.time_created], doc); } } Saturday, August 22, 2009
  • 21. Show me the code Thread Reply Result Reduce Function Sorting? [K1, V1] [K2,V2] [K1, Summary for Thread 1] num_replies: 2 [K1, RV1] group_level =1 [K2, Summary for Thread 2] [K1, RV2] num_replies: 0 Saturday, August 22, 2009
  • 22. Future Directions • Make icanhazthread real-time (Utilize the _changes API in CouchDB) • RSS Feeds (Dead simple with the CouchApp list) • etc etc Saturday, August 22, 2009
  • 23. Resources • CouchDB Wiki: http://wiki.couchdb.org • CouchDB Mailing lists (user + dev) • Blogs: Chris Anderson, Harish Mallipeddi, Jan Lenhardt • CouchDB Futon Test Suite (http://127.0.0.1:5984/_utils/ couch_tests.html) • Other CouchApps: Toast, Chris Anderson’s blog Saturday, August 22, 2009
  • 24. Thank you Q &A Saturday, August 22, 2009