0
#geekcampsg 2009
                            CouchApps - Applications built on CouchDB


                                 ...
About myself

                  •         Ruby Developer + Dabbler at Wego.com

                      •      The kick-ass ...
CouchDB FTW
                  •         Schema-less Key-Value based   •   MVCC (No Locks)
                            docu...
Profit

Saturday, August 22, 2009
CouchDB - Built for the Web
                            {
                                “_id” : “abc”,
                 ...
CouchDB - Built for the web
                              Inserting a document            HTTP PUT

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


                  Doc...
Example Map Reduce
                                       Map Function



                            function(doc) {
    ...
Example Map Reduce (contd)
                                         Reduce Function




                                fu...
Example Map Reduce (contd)
             {
                   ..
                   {
                            “key”: “S...
CouchApps


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

                  •         C...
CouchApps - Why?

                  •         Barriers to entry to develop powerful data-backed applications is
          ...
CouchApps
        •       Available at http://github.com/
                couchapp/couchapp

        •       couchapp gene...
CouchApps - List & Show Functions
                                                                            Schema-less
...
Introducing i.canhazthread.com

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

                                             nginx


                                                  ...
Document Structure
                            Thread                       Reply

      {                                ...
Interesting Map/Reduce problem
                                 (at least for me)

                                       ...
Show me the code
                                          Map Function (yawn)

                        function(doc) {
  ...
Show me the code                                 Thread        Reply         Result


                            Reduce F...
Future Directions


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

      ...
Resources
                  •         CouchDB Wiki: http://wiki.couchdb.org

                  •         CouchDB Mailing l...
Thank you


                             Q &A



Saturday, August 22, 2009
Upcoming SlideShare
Loading in...5
×

GeekCamp SG 2009 - CouchApps with CouchDB

3,307

Published on

Introduction to CouchDB and CouchApps. Example of a Rails + CouchApp hybrid built called i.canhazthread.com

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,307
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
55
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

Transcript of "GeekCamp SG 2009 - CouchApps with CouchDB"

  1. 1. #geekcampsg 2009 CouchApps - Applications built on CouchDB Arun Thampi @iamclovin http://mclov.in Saturday, August 22, 2009
  2. 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. 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
  4. 4. Profit Saturday, August 22, 2009
  5. 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. 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
  7. 7. Saturday, August 22, 2009
  8. 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. 9. Example Map Reduce Map Function function(doc) { if(doc.type == “customer”) { emit(doc.first_name, 1); } } Saturday, August 22, 2009
  10. 10. Example Map Reduce (contd) Reduce Function function(keys, values, re) { return sum(values); } Saturday, August 22, 2009
  11. 11. Example Map Reduce (contd) { .. { “key”: “Seth”, “value”: 1 }, reduce([“Seth”, “Fogell”], [1, 1]) { “key”: “Fogell”, “value”: 1 } .. } Saturday, August 22, 2009
  12. 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. 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. 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. 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. 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. 17. icanhazthread.com nginx CouchDB API [RSS, Realtime] Rails Mongrels CouchDB Saturday, August 22, 2009
  18. 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. 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. 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. 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. 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. 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. 24. Thank you Q &A Saturday, August 22, 2009
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×