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.
riak-jsJavaScript turtles all the way down           Sean Cribbs         http://whenchemistsattack.com/2008/04/25/turtles-...
Browser Server    DB
Browser   JavaScript        Java, Ruby, Server        PHP, Python    DB       SQL
Browser   JavaScript   JavaScript        Java, Ruby, Server                 node.js        PHP, Python    DB       SQL    ...
Browser   JavaScript   JavaScript   JavaScript        Java, Ruby, Server                 node.js       node.js        PHP,...
Browser   JavaScript                         JavaScript                                              JavaScript        Jav...
What about Couch? It has JavaScript.
http://captainwildchild.blogspot.com/2011/04/stopping-for-turtles.htmlWhat about Couch? It has JavaScript.
http://www.comicbookmovie.com/teenage_mutant_ninja_turtles/news/?a=18553What about Couch? It has JavaScript.
What is Riak?
What is Riak?• Distributed,  Fault-Tolerant,  Replicated
What is Riak?• Distributed,  Fault-Tolerant,  Replicated• Scales out linearly
What is Riak?• Distributed,  Fault-Tolerant,  Replicated• Scales out linearly• Flexible data  model
What is Riak?• Distributed,  Fault-Tolerant,  Replicated• Scales out linearly• Flexible data  model
What is Riak?                       PLUS                            IPT!• Distributed,      JAVASCR  Fault-Tolerant,  Repl...
riakjs.org
Getting Started
Getting Started Install Riak or Riak Search:http://downloads.basho.com
Getting Started    Install Riak or Riak Search:   http://downloads.basho.com$ npm install riak-js@latest
Getting Started    Install Riak or Riak Search:   http://downloads.basho.com$ npm install riak-js@latest$ git clone git://...
Getting Started    Install Riak or Riak Search:   http://downloads.basho.com$ npm install riak-js@latest$ git clone git://...
Basic ClientOperations               http://ijustwanttofitin.com/tag/rally-cars/
Basic Operations
Basic Operations// Get a client (pass options if needed)var db = require(riak-js).getClient()
Basic Operations// Get a client (pass options if needed)var db = require(riak-js).getClient()// Fetch an objectdb.get(conf...
Basic Operations// Get a client (pass options if needed)var db = require(riak-js).getClient()// Fetch an object           ...
Basic Operations// Get a client (pass options if needed)var db = require(riak-js).getClient()// Fetch an object           ...
Basic Operations           Picture: http://www.scooponpets.com/Turtlesaspets.html
Basic Operations// Delete an objectdb.remove(conferences, nodeconf)                                       Picture: http://...
Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)//...
Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)//...
Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)//...
Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)//...
Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)//...
Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)//...
Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb)    function cb(err, data, META){ }          Picture: http://chronotron...
Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb)
Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb)  • Request-time metadata
Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb)  • Request-time metadata   •contentType
Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb)  • Request-time metadata   •contentType   •clientId
Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb)  • Request-time metadata   •contentType   •clientId   • links, usermeta
Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb)  • Request-time metadata   •contentType   •clientId   • links, usermet...
Meta Objectfunction cb(err, data, META){ }
Meta Object function cb(err, data, META){ }• Response-time metadata
Meta Object function cb(err, data, META){ }• Response-time metadata • bucket, key, vclock
Meta Object function cb(err, data, META){ }• Response-time metadata • bucket, key, vclock • links, usermeta
Meta Object function cb(err, data, META){ }• Response-time metadata • bucket, key, vclock • links, usermeta • lastMod, eta...
Using Meta
Using Meta// Add a link to the objectdb.get(frameworks, node.js,  function(err, data, meta){    meta.addLink({bucket:vm, k...
Using Meta// Add a link to the objectdb.get(frameworks, node.js,  function(err, data, meta){    meta.addLink({bucket:vm, k...
Querying Beyond  Key-Value   Picture: http://greencs.files.wordpress.com/2008/07/turtle-                              nom.jpg
Link-walking      Picture: http://fisherwy.blogspot.com/2007/09/two-headed-turtle-at-big-al-                               ...
Link-walking// Find friendsdb.walk(people, sean,        [[_,friend]])                            Picture: http://fisherwy.b...
Link-walking// Find friendsdb.walk(people, sean,        [[_,friend]])// Find acquaintances of friendsdb.walk(people, mathi...
Link-walking// Find friendsdb.walk(people, sean,        [[_,friend]])// Find acquaintances of friendsdb.walk(people, mathi...
Wait. You said Riakhad JavaScript in it!                                           U MAD?      Picture: http://arsnotoria....
MapReduce
MapReduce  list of keys
MapReduce                 list of keysmap()    map()      map()       map()   map()
MapReduce                 list of keysmap()    map()      map()       map()   map()                   reduce()
MapReduce                 list of keysmap()    map()      map()       map()   map()                   reduce()            ...
MapReduce                 list of keys                       JSONmap()    map()      map()       map()   map()            ...
MapReduce                            list of keys                                  JSON       map()       map()       map(...
MapReduce                            list of keys                                  JSON       map()       map()       map(...
MapReduce                            list of keys                                  JSON       map()       map()       map(...
MapReduce
MapReduce// Execute a MapReduce querydb.add(frameworks)         // Use all keys in bucket  .map(Riak.mapValuesJson) // Map...
MapReduce// Execute a MapReduce querydb.add(frameworks)         // Use all keys in bucket  .map(Riak.mapValuesJson) // Map...
MapReduce
MapReduce// Initiate MapReduce with a key-filterdb.add({ bucket: emails,         key_filters: [["ends_with", "basho.com"]]...
Riak Search
Riak Search// Turn on automatic document indexingdb.enableIndex(documents)
Riak Search// Turn on automatic document indexingdb.enableIndex(documents)// Perform a simple searchdb.search(documents, t...
Riak Search// Turn on automatic document indexingdb.enableIndex(documents)// Perform a simple searchdb.search(documents, t...
etc.
etc.• Session Store
etc.• Session Store• Mini-Riak Test Server
etc.• Session Store• Mini-Riak Test Server• Multi-protocol (HTTP, Protobuffs)
etc.• Session Store• Mini-Riak Test Server• Multi-protocol (HTTP, Protobuffs)• Luwak (large files)
COME AT ME BRO   Picture: http://fl.biology.usgs.gov/posters/Herpetology/Snapping_Turtles/snapping_turtles.html            ...
Questions?
Questions?     sean@basho.com       @seancribbs    jsconf.basho.com
Riak on Turtles                           (someday)Picture: http://scienceblogs.com/bioephemera/2008/07/gpsequipped_box_tu...
Upcoming SlideShare
Loading in …5
×

riak-js: Javascript Turtles All the Way Down

9,495 views

Published on

riak-js is an awesome client driver for the Riak distributed datastore.

Published in: Technology
  • Be the first to comment

riak-js: Javascript Turtles All the Way Down

  1. 1. riak-jsJavaScript turtles all the way down Sean Cribbs http://whenchemistsattack.com/2008/04/25/turtles-all-the-way-down/
  2. 2. Browser Server DB
  3. 3. Browser JavaScript Java, Ruby, Server PHP, Python DB SQL
  4. 4. Browser JavaScript JavaScript Java, Ruby, Server node.js PHP, Python DB SQL SQL
  5. 5. Browser JavaScript JavaScript JavaScript Java, Ruby, Server node.js node.js PHP, Python DB SQL SQL JavaScript?!
  6. 6. Browser JavaScript JavaScript JavaScript Java, Ruby, Server node.js node.js PHP, Python DB SQL SQL JavaScript?! http://animals.nationalgeographic.com/animals/reptiles/kemps-ridley-sea-turtle/
  7. 7. What about Couch? It has JavaScript.
  8. 8. http://captainwildchild.blogspot.com/2011/04/stopping-for-turtles.htmlWhat about Couch? It has JavaScript.
  9. 9. http://www.comicbookmovie.com/teenage_mutant_ninja_turtles/news/?a=18553What about Couch? It has JavaScript.
  10. 10. What is Riak?
  11. 11. What is Riak?• Distributed, Fault-Tolerant, Replicated
  12. 12. What is Riak?• Distributed, Fault-Tolerant, Replicated• Scales out linearly
  13. 13. What is Riak?• Distributed, Fault-Tolerant, Replicated• Scales out linearly• Flexible data model
  14. 14. What is Riak?• Distributed, Fault-Tolerant, Replicated• Scales out linearly• Flexible data model
  15. 15. What is Riak? PLUS IPT!• Distributed, JAVASCR Fault-Tolerant, Replicated• Scales out linearly• Flexible data model
  16. 16. riakjs.org
  17. 17. Getting Started
  18. 18. Getting Started Install Riak or Riak Search:http://downloads.basho.com
  19. 19. Getting Started Install Riak or Riak Search: http://downloads.basho.com$ npm install riak-js@latest
  20. 20. Getting Started Install Riak or Riak Search: http://downloads.basho.com$ npm install riak-js@latest$ git clone git://github.com/frank06/riak-js
  21. 21. Getting Started Install Riak or Riak Search: http://downloads.basho.com$ npm install riak-js@latest$ git clone git://github.com/frank06/riak-js
  22. 22. Basic ClientOperations http://ijustwanttofitin.com/tag/rally-cars/
  23. 23. Basic Operations
  24. 24. Basic Operations// Get a client (pass options if needed)var db = require(riak-js).getClient()
  25. 25. Basic Operations// Get a client (pass options if needed)var db = require(riak-js).getClient()// Fetch an objectdb.get(conferences, nodeconf,  function(err, data) {    console.log("Found the conference:" + sys.inspect(data))  })
  26. 26. Basic Operations// Get a client (pass options if needed)var db = require(riak-js).getClient()// Fetch an object typical nodedb.get(conferences, nodeconf, callback style  function(err, data) {    console.log("Found the conference:" + sys.inspect(data))  })
  27. 27. Basic Operations// Get a client (pass options if needed)var db = require(riak-js).getClient()// Fetch an object typical nodedb.get(conferences, nodeconf, callback style  function(err, data) {    console.log("Found the conference:" + sys.inspect(data))  })// Store an objectdb.save(conferences, nodeconf,        {date:"2011-05-05",         title: "nodeconf 2011",         presenters: ["Sean Cribbs"]})
  28. 28. Basic Operations Picture: http://www.scooponpets.com/Turtlesaspets.html
  29. 29. Basic Operations// Delete an objectdb.remove(conferences, nodeconf) Picture: http://www.scooponpets.com/Turtlesaspets.html
  30. 30. Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)// Stream the keys (on master) Picture: http://www.scooponpets.com/Turtlesaspets.html
  31. 31. Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)// Stream the keys (on master)db.keys(frameworks,{keys:stream}). on(keys, cb).start() Picture: http://www.scooponpets.com/Turtlesaspets.html
  32. 32. Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)// Stream the keys (on master)db.keys(frameworks,{keys:stream}). on(keys, cb).start()// Give me them alldb.getAll(frameworks) Picture: http://www.scooponpets.com/Turtlesaspets.html
  33. 33. Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)// Stream the keys (on master)db.keys(frameworks,{keys:stream}). on(keys, cb).start()// Give me them alldb.getAll(frameworks) Picture: http://www.scooponpets.com/Turtlesaspets.html
  34. 34. Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)// Stream the keys (on master)db.keys(frameworks,{keys:stream}). on(keys, cb).start()// Give me them alldb.getAll(frameworks)// How many are there? (counts keys) Picture: http://www.scooponpets.com/Turtlesaspets.html
  35. 35. Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)// Stream the keys (on master)db.keys(frameworks,{keys:stream}). on(keys, cb).start()// Give me them alldb.getAll(frameworks)// How many are there? (counts keys)db.count(frameworks) Picture: http://www.scooponpets.com/Turtlesaspets.html
  36. 36. Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb) function cb(err, data, META){ } Picture: http://chronotron.files.wordpress.com/2010/07/turtles.png
  37. 37. Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb)
  38. 38. Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb) • Request-time metadata
  39. 39. Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb) • Request-time metadata •contentType
  40. 40. Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb) • Request-time metadata •contentType •clientId
  41. 41. Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb) • Request-time metadata •contentType •clientId • links, usermeta
  42. 42. Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb) • Request-time metadata •contentType •clientId • links, usermeta • quorums (r,w,dw), returnBody
  43. 43. Meta Objectfunction cb(err, data, META){ }
  44. 44. Meta Object function cb(err, data, META){ }• Response-time metadata
  45. 45. Meta Object function cb(err, data, META){ }• Response-time metadata • bucket, key, vclock
  46. 46. Meta Object function cb(err, data, META){ }• Response-time metadata • bucket, key, vclock • links, usermeta
  47. 47. Meta Object function cb(err, data, META){ }• Response-time metadata • bucket, key, vclock • links, usermeta • lastMod, etag, statusCode
  48. 48. Using Meta
  49. 49. Using Meta// Add a link to the objectdb.get(frameworks, node.js,  function(err, data, meta){    meta.addLink({bucket:vm, key:v8, tag:vm});    db.save(frameworks, node.js, data, meta)  })
  50. 50. Using Meta// Add a link to the objectdb.get(frameworks, node.js,  function(err, data, meta){    meta.addLink({bucket:vm, key:v8, tag:vm});    db.save(frameworks, node.js, data, meta)  })// Set the content typedb.save(pages, index.html,        <html><body>Hello, world!</body></html>,        {contentType: html})
  51. 51. Querying Beyond Key-Value Picture: http://greencs.files.wordpress.com/2008/07/turtle- nom.jpg
  52. 52. Link-walking Picture: http://fisherwy.blogspot.com/2007/09/two-headed-turtle-at-big-al- aquarium.html
  53. 53. Link-walking// Find friendsdb.walk(people, sean, [[_,friend]]) Picture: http://fisherwy.blogspot.com/2007/09/two-headed-turtle-at-big-al- aquarium.html
  54. 54. Link-walking// Find friendsdb.walk(people, sean, [[_,friend]])// Find acquaintances of friendsdb.walk(people, mathias,        [[_,friend], Picture: http://fisherwy.blogspot.com/2007/09/two-headed-turtle-at-big-al- aquarium.html
  55. 55. Link-walking// Find friendsdb.walk(people, sean, [[_,friend]])// Find acquaintances of friendsdb.walk(people, mathias,        [[_,friend],         [people,_]]) Picture: http://fisherwy.blogspot.com/2007/09/two-headed-turtle-at-big-al- aquarium.html
  56. 56. Wait. You said Riakhad JavaScript in it! U MAD? Picture: http://arsnotoria.blogspot.com/2010_04_18_archive.html
  57. 57. MapReduce
  58. 58. MapReduce list of keys
  59. 59. MapReduce list of keysmap() map() map() map() map()
  60. 60. MapReduce list of keysmap() map() map() map() map() reduce()
  61. 61. MapReduce list of keysmap() map() map() map() map() reduce() results
  62. 62. MapReduce list of keys JSONmap() map() map() map() map() reduce() results
  63. 63. MapReduce list of keys JSON map() map() map() map() map()JavaScript JavaScript JavaScript JavaScript JavaScript reduce() results
  64. 64. MapReduce list of keys JSON map() map() map() map() map()JavaScript JavaScript JavaScript JavaScript JavaScript reduce() JavaScript results
  65. 65. MapReduce list of keys JSON map() map() map() map() map()JavaScript JavaScript JavaScript JavaScript JavaScript reduce() JavaScript results JSON
  66. 66. MapReduce
  67. 67. MapReduce// Execute a MapReduce querydb.add(frameworks) // Use all keys in bucket  .map(Riak.mapValuesJson) // Map using a built-in  .run(function(err, data){ // Execute the query         console.log(data);       })
  68. 68. MapReduce// Execute a MapReduce querydb.add(frameworks) // Use all keys in bucket  .map(Riak.mapValuesJson) // Map using a built-in  .run(function(err, data){ // Execute the query         console.log(data);       })// Send a focused querydb.add(frameworks, node.js) // Start with one key  .link({ bucket: "vm"}) // Follow some links  .map(function(obj){ // Map using an inline         var data =            Riak.mapValuesJson(obj)[0];         return [data.name]       })  .reduce(Riak.reduceSort) // Sort via reduce  .run()
  69. 69. MapReduce
  70. 70. MapReduce// Initiate MapReduce with a key-filterdb.add({ bucket: emails,         key_filters: [["ends_with", "basho.com"]] }) // Map with a phase-argument  .map({ name:Riak.mapByFields,         arg: { joined:2010-01-01 })  .run()
  71. 71. Riak Search
  72. 72. Riak Search// Turn on automatic document indexingdb.enableIndex(documents)
  73. 73. Riak Search// Turn on automatic document indexingdb.enableIndex(documents)// Perform a simple searchdb.search(documents, title:scalable)
  74. 74. Riak Search// Turn on automatic document indexingdb.enableIndex(documents)// Perform a simple searchdb.search(documents, title:scalable)// Start a MapReduce query with searchdb.addSearch(documents, title:scalable)// From here, add map and reduce phases
  75. 75. etc.
  76. 76. etc.• Session Store
  77. 77. etc.• Session Store• Mini-Riak Test Server
  78. 78. etc.• Session Store• Mini-Riak Test Server• Multi-protocol (HTTP, Protobuffs)
  79. 79. etc.• Session Store• Mini-Riak Test Server• Multi-protocol (HTTP, Protobuffs)• Luwak (large files)
  80. 80. COME AT ME BRO Picture: http://fl.biology.usgs.gov/posters/Herpetology/Snapping_Turtles/snapping_turtles.html Demo Timehttps://github.com/basho/riaktant
  81. 81. Questions?
  82. 82. Questions? sean@basho.com @seancribbs jsconf.basho.com
  83. 83. Riak on Turtles (someday)Picture: http://scienceblogs.com/bioephemera/2008/07/gpsequipped_box_turtle_leads_p.php

×