riak-js: Javascript Turtles All the Way Down

8,447
-1

Published on

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

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

No Downloads
Views
Total Views
8,447
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
16
Embeds 0
No embeds

No notes for slide
  • \n
  • Like all these turtles marching toward the sea, we’re on a path. And that path is the adoption of JavaScript in lots of places it hasn’t been before.\n
  • Like all these turtles marching toward the sea, we’re on a path. And that path is the adoption of JavaScript in lots of places it hasn’t been before.\n
  • Like all these turtles marching toward the sea, we’re on a path. And that path is the adoption of JavaScript in lots of places it hasn’t been before.\n
  • Like all these turtles marching toward the sea, we’re on a path. And that path is the adoption of JavaScript in lots of places it hasn’t been before.\n
  • So you’re probably saying “What about CouchDB? It has JavaScript”. \n\nCouchDB is great. I like it a lot. (apologies for the strawman) But it has been my experience that the types of applications people build on top of CouchDB are very different from the types of apps people build with Node.js. And you don’t want to end up like this turtle.\n\nYou want to be like these turtles!\n
  • So you’re probably saying “What about CouchDB? It has JavaScript”. \n\nCouchDB is great. I like it a lot. (apologies for the strawman) But it has been my experience that the types of applications people build on top of CouchDB are very different from the types of apps people build with Node.js. And you don’t want to end up like this turtle.\n\nYou want to be like these turtles!\n
  • So you’re probably saying “What about CouchDB? It has JavaScript”. \n\nCouchDB is great. I like it a lot. (apologies for the strawman) But it has been my experience that the types of applications people build on top of CouchDB are very different from the types of apps people build with Node.js. And you don’t want to end up like this turtle.\n\nYou want to be like these turtles!\n
  • So you’re probably saying “What about CouchDB? It has JavaScript”. \n\nCouchDB is great. I like it a lot. (apologies for the strawman) But it has been my experience that the types of applications people build on top of CouchDB are very different from the types of apps people build with Node.js. And you don’t want to end up like this turtle.\n\nYou want to be like these turtles!\n
  • * “Your data is safe with us.”\n* “Just add more machines.”\n* “Key-Value++, MapReduce, Search. With great power comes great responsibility - take ownership of your data.”\n
  • * “Your data is safe with us.”\n* “Just add more machines.”\n* “Key-Value++, MapReduce, Search. With great power comes great responsibility - take ownership of your data.”\n
  • * “Your data is safe with us.”\n* “Just add more machines.”\n* “Key-Value++, MapReduce, Search. With great power comes great responsibility - take ownership of your data.”\n
  • * “Your data is safe with us.”\n* “Just add more machines.”\n* “Key-Value++, MapReduce, Search. With great power comes great responsibility - take ownership of your data.”\n
  • * “Your data is safe with us.”\n* “Just add more machines.”\n* “Key-Value++, MapReduce, Search. With great power comes great responsibility - take ownership of your data.”\n
  • So if you want to work with Riak from node.js, Francisco Treacy <point him out> wrote this awesome driver called riak-js. It’s also got a beautiful website at riakjs.org that is envy of all READMEs.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Hosted on no.de\n
  • \n
  • \n
  • \n
  • 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

    ×