Persistence Smoothie

693 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
693
On SlideShare
0
From Embeds
0
Number of Embeds
52
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide






















































  • Persistence Smoothie

    1. 1. Persistence Smoothie Flip  Sasser @flipsasser Blending  SQL  and  NoSQL
    2. 2. h6p://github.com/flipsasser/Persistence-­‐Smoothie
    3. 3. NooooooSQL
    4. 4. Photo  credit:  h6p://www.flickr.com/photos/2493/
    5. 5. Persistence
    6. 6. No ACID Sacrifices  transacHons  and  consistency  for  performance
    7. 7. Keep what you know You  shouldn’t  be  running  *just*  NoSQL  at  all  Hmes
    8. 8. •Key-Value Stores •Document Stores •Column-based Stores •Graph Stores
    9. 9. •Key-Value Stores •Document Stores •Column-based Stores •Graph Stores
    10. 10. •Redis •Voldemort •Tokyo Cabinet •Riak •MemcachedDB
    11. 11. •Key-Value Stores •Document Stores •Column-based Stores •Graph Stores
    12. 12. •CouchDB •Riak •MongoDB •FleetDB
    13. 13. Map/Reduce map = function() { this.tags.forEach(function(tag) { emit(tag, {count: 1}); }); } reduce = function(key, values) { var total = 0; for (var i = 0; i < values.length; i++) { total += values[i].count; } return {count: total}; }
    14. 14. •Key-Value Stores •Document Stores •Column-based Stores •Graph Stores
    15. 15. •Cassandra •HBase
    16. 16. •Key-Value Stores •Document Stores •Column-based Stores •Graph Stores
    17. 17. •Neo4j •HypergraphDB •InfoGrid
    18. 18. Use Cases
    19. 19. Use Cases Key-­‐Value  Store:  Ugly  joins  =>  denormalized  data
    20. 20. Use Cases Document  Store:  Loose  schema,  no  ACID
    21. 21. Use Cases Graph  Store:  Deep  relaHonships
    22. 22. Ready to jump in?
    23. 23. Too bad. You’re  already  using  SQL.
    24. 24. Let’s mix it together
    25. 25. First Attempt Do  it  by  hand
    26. 26. class Post include MongoMapper::Document key :title, String key :body, String key :tags, Array key :user_id, Integer def user User.find_by_id(self.user_id) end def user=(some_user) self.user_id = some_user.id end end class User < ActiveRecord::Base def posts(options = {}) Post.all({:conditions => {:user_id => self.id}}.merge(options)) end end
    27. 27. Simple I  mean,  it  “works”
    28. 28. Fat, wet models
    29. 29. Second Attempt DataMapper  to  the  rescue
    30. 30. Photo  credit:  h6p://www.flickr.com/photos/myklrovenHne
    31. 31. DataMapper.setup(:default, "mysql://localhost") DataMapper.setup(:mongodb, "mongo://localhost/posts") class Post include DataMapper::Resource def self.default_repository_name; :mongodb; end property :title, String property :body, String property :tags, Array belongs_to :user end class User include DataMapper::Resource property :email, String property :name, String has n, :posts end
    32. 32. Simpler And  it  sHll  works
    33. 33. Ready to refactor? I’ve  sHll  got  all  this  AcHveRecord  lying  around...
    34. 34. Go easy
    35. 35. Store App
    36. 36. •Authentication •Products •Purchases •Activity stream
    37. 37. •Authentication •Products •Purchases •Activity stream
    38. 38. gem install devise Looks  like  we  can  keep  our  SQL
    39. 39. •Authentication •Products •Purchases •Activity stream
    40. 40. Weight Category Country  of  Origin Size Year Dimensions Producer Label Author SKU Genre Ports ISBN Color ASIN
    41. 41. Metadata Don’t  need  ACID;  need  flexibility:  Document  store
    42. 42. •Authentication •Products •Purchases •Activity stream
    43. 43. Transactions Okay,  more  SQL
    44. 44. •Authentication •Products •Purchases •Activity stream
    45. 45. JOIN city Denormalize  with  a  Key-­‐Value  store
    46. 46. Okay, let’s code
    47. 47. Mix it up Don’t  be  afraid  to  build  something  with  a  lot  of  moving   parts
    48. 48. Drawbacks
    49. 49. DataPortability.nil? #=>  true
    50. 50. Photo  credit:  h6p://www.flickr.com/photos/francoisroche
    51. 51. gem uninstall everything Say  goodbye  to  your  fun  AR  mixins
    52. 52. Okay, thanks Now  I  can  relax
    53. 53. @flipsasser Thanks  to  @mbleigh

    ×