Persistence Smoothie
Upcoming SlideShare
Loading in...5
×
 

Persistence Smoothie

on

  • 874 views

 

Statistics

Views

Total Views
874
Views on SlideShare
823
Embed Views
51

Actions

Likes
0
Downloads
4
Comments
0

3 Embeds 51

http://en.oreilly.com 40
http://www.slideshare.net 6
http://speakerrate.com 5

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Persistence Smoothie Persistence Smoothie Presentation Transcript

  • Persistence Smoothie Flip  Sasser @flipsasser Blending  SQL  and  NoSQL
  • h6p://github.com/flipsasser/Persistence-­‐Smoothie
  • NooooooSQL
  • Photo  credit:  h6p://www.flickr.com/photos/2493/
  • Persistence
  • No ACID Sacrifices  transacHons  and  consistency  for  performance
  • Keep what you know You  shouldn’t  be  running  *just*  NoSQL  at  all  Hmes
  • •Key-Value Stores •Document Stores •Column-based Stores •Graph Stores
  • •Key-Value Stores •Document Stores •Column-based Stores •Graph Stores
  • •Redis •Voldemort •Tokyo Cabinet •Riak •MemcachedDB
  • •Key-Value Stores •Document Stores •Column-based Stores •Graph Stores
  • •CouchDB •Riak •MongoDB •FleetDB
  • 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}; }
  • •Key-Value Stores •Document Stores •Column-based Stores •Graph Stores
  • •Cassandra •HBase
  • •Key-Value Stores •Document Stores •Column-based Stores •Graph Stores
  • •Neo4j •HypergraphDB •InfoGrid
  • Use Cases
  • Use Cases Key-­‐Value  Store:  Ugly  joins  =>  denormalized  data
  • Use Cases Document  Store:  Loose  schema,  no  ACID
  • Use Cases Graph  Store:  Deep  relaHonships
  • Ready to jump in?
  • Too bad. You’re  already  using  SQL.
  • Let’s mix it together
  • First Attempt Do  it  by  hand
  • 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
  • Simple I  mean,  it  “works”
  • Fat, wet models
  • Second Attempt DataMapper  to  the  rescue
  • Photo  credit:  h6p://www.flickr.com/photos/myklrovenHne
  • 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
  • Simpler And  it  sHll  works
  • Ready to refactor? I’ve  sHll  got  all  this  AcHveRecord  lying  around...
  • Go easy
  • Store App
  • •Authentication •Products •Purchases •Activity stream
  • •Authentication •Products •Purchases •Activity stream
  • gem install devise Looks  like  we  can  keep  our  SQL
  • •Authentication •Products •Purchases •Activity stream
  • Weight Category Country  of  Origin Size Year Dimensions Producer Label Author SKU Genre Ports ISBN Color ASIN
  • Metadata Don’t  need  ACID;  need  flexibility:  Document  store
  • •Authentication •Products •Purchases •Activity stream
  • Transactions Okay,  more  SQL
  • •Authentication •Products •Purchases •Activity stream
  • JOIN city Denormalize  with  a  Key-­‐Value  store
  • Okay, let’s code
  • Mix it up Don’t  be  afraid  to  build  something  with  a  lot  of  moving   parts
  • Drawbacks
  • DataPortability.nil? #=>  true
  • Photo  credit:  h6p://www.flickr.com/photos/francoisroche
  • gem uninstall everything Say  goodbye  to  your  fun  AR  mixins
  • Okay, thanks Now  I  can  relax
  • @flipsasser Thanks  to  @mbleigh