Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

An introduction to CouchDB

11,870 views

Published on

This is a talk I presented at University Limerick to give people an introduction into CouchDB.

What is it? How does it generally work? Introducing new concepts, etc.

Published in: Technology, Education
  • Hi there! Get Your Professional Job-Winning Resume Here - Check our website! http://bit.ly/resumpro
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • On slide 35, please note that there should be a '-d' before the curl JSON argument.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

An introduction to CouchDB

  1. 1. An introduction to #CouchDB Sit back and relax @davidcoallier, University Limerick 2010
  2. 2. WTF IS COUCH? - Highly concurrent database server - Schema free, document based database - RESTFul API - Map/Reduce Views generation - EASY replication (like... really)
  3. 3. ... AGAIN.. WTF?!
  4. 4. HISTORY CLASS TIME!
  5. 5. 32 CouchDB servers 2 datacenters SSL based user auth, sharding, etc. This is the only BBC transparent logo I found and it’s not BBC World News using CouchDB but BBC. See: http://www.erlang-factory.com/conference/London2009/speakers/endafarrell
  6. 6. Ubuntu One
  7. 7. mozilla.org IBM Apple myspace.com ebay meebo oh so many more.
  8. 8. DOCUMENT BASED KEY/VALUE STORE...
  9. 9. key value name david email e@e.com phones Array createdAt timetsamp
  10. 10. DOCUMENT BASED WHAT? - Dictionary of data - JSON Objects - A doc can have attachments - Auto generated IDs (CLAP NOW) - Revisions (THAT’S RIGHT..)
  11. 11. DOCUMENT { "_id": "3fc3b3bf3c101e15fa7d08e2ecf9c900", "_rev": "1-34c5c7adcf1fdb8898498d1e6b64ebdd", "firstname": "David", "email": "david@echolibre.com" }
  12. 12. DOCUMENT { "_id": "3fc3b3bf3c101e15fa7d08e2ecf9c900", "_rev": "1-34c5c7adcf1fdb8898498d1e6b64ebdd", "firstname": "David", "email": "david@echolibre.com", "phones": { "mobile": "086x209x69", "home": "none" }, "createdAt": "2009-09-16T22:12:43Z" }
  13. 13. key value name david email e@e.com phones Array createdAt timetsamp
  14. 14. WHAT ABOUT MY CRUD? - Create PUT /db/docid - Retrieve GET /db/docid - Update POST /db/docid - Delete DELETE /db/docid
  15. 15. VIEWS - Persistent representation of docs - Prod is solid. No _temp shit. - Javascript, Erlang, Python, wtf ever.
  16. 16. MAP/REDUCE ...
  17. 17. JAVASCRIPT
  18. 18. MAP map: function(doc) { if (doc.firstname) { emit(doc.firstname, doc); } }
  19. 19. MAP %% Map Function fun({Doc}) -> case {proplists:get_value(<<"firstname">>, Doc)} of {undefined} -> false; {Name} -> Emit(Name, Doc); _ -> ok end end.
  20. 20. fun({Doc}) -> Emitter = fun(Doc) -> Name = proplists:get_value(<<"name">>, Doc, null), Emit(Name, Doc) end, HasRequiredFields = fun(Doc) -> case {proplists:is_defined(<<"firstname">>, Doc)} of {true} -> Emitter(Doc); _-> false end end, HasRequiredFields(Doc) end.
  21. 21. MAP/REDUCE EXAMPLE
  22. 22. MAP { "_id": "3fc3b3bf3c101e15fa7d08e2ecf9c900", "_rev": "1-34c5c7adcf1fdb8898498d1e6b64ebdd", "firstname": "David", "email": "david@echolibre.com", "phones": { "mobile": "086x209x69", "home": "none" }, "createdAt": "2009-09-16T22:12:43Z", "tags": ["cool", "php", "couchdb", "skynet"] }
  23. 23. MAP map: function(doc) { if (doc.tags && docs.tags.length > 0) { for (var i = 0; i < doc.tags.length; i++) { emit(doc.tags[i], 1); } } }
  24. 24. REDUCE map: function(doc) { if (doc.tags && docs.tags.length > 0) { for (var i = 0; i < doc.tags.length; i++) { emit(doc.tags[i], 1); } } }, reduce: function(tag, counts) { int sum = 0; for(var i = 0; i < counts.length; i++) { sum += counts[i]; } return sum; }
  25. 25. REDUCE function(tag, counts) { int sum = 0; for(var i = 0; i < counts.length; i++) { sum += counts[i]; } return sum; }
  26. 26. REDUCE { "total_rows":4, "rows":[ { "key":"cool", "value":1}, { "key":"php", "value":1}, { "key":"couchdb", "value":1}, { "key":"skynet", "value":1}, ] }
  27. 27. REDUCE TRICKS map: function(doc) { if (doc.tags && docs.tags.length > 0) { for (var i = 0; i < doc.tags.length; i++) { emit(doc.tags[i], 1); } } } reduce: "_count"
  28. 28. REDUCE { "total_rows":4, "rows":[ { "key":"cool", "value":1}, { "key":"php", "value":1}, { "key":"couchdb", "value":1}, { "key":"skynet", "value":1}, ] }
  29. 29. REDUCE map: function(doc) { if (doc.tags && docs.tags.length > 0) { for (var i = 0; i < doc.tags.length; i++) { emit(doc.tags[i], "yer ma"); } } }, reduce: function (tag, count) { return sum(tag); }
  30. 30. THEN...
  31. 31. BEWARE OF REDUCE VALUES
  32. 32. REPLICATION It fuckin’ rules.
  33. 33. REPLICATION Easy (See later futon ;-)) Continuous... or not :P Replicates your views Replicate only what you need (filter?)
  34. 34. REPLICATION curl -X POST http://localhost:5984/_replicate '{"source":"/dbname", "target": "http://localhost:5555/otherdb", "continuous": true}'
  35. 35. REPLICATION Source The boss Target changes? watcha need?? target needs x, y, z save them
  36. 36. REPLICATION MASTER / SLAVES
  37. 37. REPLICATION MASTER / SLAVES
  38. 38. REPLICATION MULTI MASTER
  39. 39. REPLICATION MULTI MASTER
  40. 40. REPLICATION USE CASE Automated job to validate and test data and do bunch of shits
  41. 41. FUTON
  42. 42. FUTON
  43. 43. NOTE TO SELF. Show them. Open up CouchDBX
  44. 44. COOL THINGS Authorization CouchDB Lucene Lounge CouchDBX Couchio Cloudant A bunch of random bits and pieces
  45. 45. COMPLETE SHITE COMING UP eas r e id sha W le! NO p s peo cus Dis
  46. 46. CONCEPTS AND IDEAS Graph Theory ... ss ion u a disc t d star tr y an
  47. 47. CONCEPTS AND IDEAS Ghost Replication ... ss ion u a disc t d star tr y an
  48. 48. CONCEPTS AND IDEAS Shared Index Replication ... ss ion u a disc t d star tr y an
  49. 49. QUESTIONS?
  50. 50. ME! MEEE!!! @davidcoallier david@echolibre.com
  51. 51. THANKS
  52. 52. LINKS - https://nosqleast.com/2009/slides/miller-couchdb.pdf - http://couch.io - http://cloudant.com - http://wiki.apache.org/couchdb/CouchDB_in_the_wild - irc://couchdb@freenode.net (Bug jan___ ;-))

×