SlideShare a Scribd company logo
1 of 54
Download to read offline
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

More Related Content

What's hot (11)

Html5 n css3
Html5 n css3Html5 n css3
Html5 n css3
 
Neoworks
NeoworksNeoworks
Neoworks
 
Delivery method
Delivery methodDelivery method
Delivery method
 
Azure App Configuration with .NET applications
Azure App Configuration with .NET applicationsAzure App Configuration with .NET applications
Azure App Configuration with .NET applications
 
Alloy
AlloyAlloy
Alloy
 
BarCamp cloudsearch
BarCamp cloudsearchBarCamp cloudsearch
BarCamp cloudsearch
 
Web designing course content
Web designing course contentWeb designing course content
Web designing course content
 
Essential ElixirScript - Roman Senin
Essential ElixirScript - Roman SeninEssential ElixirScript - Roman Senin
Essential ElixirScript - Roman Senin
 
USAGE OF DATABASE IN SOFTWARE DEVELOPMENT
USAGE OF DATABASE IN SOFTWARE DEVELOPMENTUSAGE OF DATABASE IN SOFTWARE DEVELOPMENT
USAGE OF DATABASE IN SOFTWARE DEVELOPMENT
 
Riding rails for 10 years
Riding rails for 10 yearsRiding rails for 10 years
Riding rails for 10 years
 
CSS Flexbox and Grid Layouts
CSS Flexbox and Grid LayoutsCSS Flexbox and Grid Layouts
CSS Flexbox and Grid Layouts
 

Similar to Persistence Smoothie

Building Big Data Solutions with Azure Data Lake.10.11.17.pptx
Building Big Data Solutions with Azure Data Lake.10.11.17.pptxBuilding Big Data Solutions with Azure Data Lake.10.11.17.pptx
Building Big Data Solutions with Azure Data Lake.10.11.17.pptx
thando80
 
How Shopify Scales Rails
How Shopify Scales RailsHow Shopify Scales Rails
How Shopify Scales Rails
jduff
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
Avi Kedar
 

Similar to Persistence Smoothie (20)

CouchDB introduction
CouchDB introductionCouchDB introduction
CouchDB introduction
 
Building Big Data Solutions with Azure Data Lake.10.11.17.pptx
Building Big Data Solutions with Azure Data Lake.10.11.17.pptxBuilding Big Data Solutions with Azure Data Lake.10.11.17.pptx
Building Big Data Solutions with Azure Data Lake.10.11.17.pptx
 
How Shopify Scales Rails
How Shopify Scales RailsHow Shopify Scales Rails
How Shopify Scales Rails
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
 
Client storage
Client storageClient storage
Client storage
 
Beyond Relational
Beyond RelationalBeyond Relational
Beyond Relational
 
Scaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLScaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQL
 
Best practices on Building a Big Data Analytics Solution (SQLBits 2018 Traini...
Best practices on Building a Big Data Analytics Solution (SQLBits 2018 Traini...Best practices on Building a Big Data Analytics Solution (SQLBits 2018 Traini...
Best practices on Building a Big Data Analytics Solution (SQLBits 2018 Traini...
 
Scalable web architecture
Scalable web architectureScalable web architecture
Scalable web architecture
 
SQL To NoSQL - Top 6 Questions Before Making The Move
SQL To NoSQL - Top 6 Questions Before Making The MoveSQL To NoSQL - Top 6 Questions Before Making The Move
SQL To NoSQL - Top 6 Questions Before Making The Move
 
KeyValue Stores
KeyValue StoresKeyValue Stores
KeyValue Stores
 
Harness SharePoint and jQuery to Make Dynamic Displays and Applications
 Harness SharePoint and jQuery to Make Dynamic Displays and Applications Harness SharePoint and jQuery to Make Dynamic Displays and Applications
Harness SharePoint and jQuery to Make Dynamic Displays and Applications
 
High-Performance Storage Services with HailDB and Java
High-Performance Storage Services with HailDB and JavaHigh-Performance Storage Services with HailDB and Java
High-Performance Storage Services with HailDB and Java
 
Android lessons you won't learn in school
Android lessons you won't learn in schoolAndroid lessons you won't learn in school
Android lessons you won't learn in school
 
Cloud Big Data Architectures
Cloud Big Data ArchitecturesCloud Big Data Architectures
Cloud Big Data Architectures
 
Accelerating NoSQL
Accelerating NoSQLAccelerating NoSQL
Accelerating NoSQL
 
MongoDB, E-commerce and Transactions
MongoDB, E-commerce and TransactionsMongoDB, E-commerce and Transactions
MongoDB, E-commerce and Transactions
 
Rails 3.1
Rails 3.1Rails 3.1
Rails 3.1
 
Build a modern data platform.pptx
Build a modern data platform.pptxBuild a modern data platform.pptx
Build a modern data platform.pptx
 
Next Generation Data Platforms - Deon Thomas
Next Generation Data Platforms - Deon ThomasNext Generation Data Platforms - Deon Thomas
Next Generation Data Platforms - Deon Thomas
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Persistence Smoothie

Editor's Notes