SlideShare a Scribd company logo
DATABASE
MULTITENANCY
RUBY IDIOM CASE
TYPICAL MULTITENANCY OPTIONS
SQL WORLD
SHARED
Same Database
Different Schema
ISOLATED
TYPICAL MULTITENANCY OPTIONS
SQL WORLD
SHARED
Same Database
Different Schema
Different Database
Same Schema
ISOLATED
TYPICAL MULTITENANCY OPTIONS
SQL WORLD
SHARED
Same Database
Different Schema
Different Database
Same Schema
Different Database
Different Schema
ISOLATED
TYPICAL MULTITENANCY OPTIONS
SQL WORLD
SCHEMA-LESS WORLD - MONGODB
SHARED
Same Database
Different Schema
Different Database
Same Schema
Different Database
Different Schema
ISOLATED
SHARED
Same Database
Different Collection
ISOLATED
TYPICAL MULTITENANCY OPTIONS
SQL WORLD
SCHEMA-LESS WORLD - MONGODB
SHARED
Same Database
Different Schema
Different Database
Same Schema
Different Database
Different Schema
ISOLATED
SHARED
Same Database
Different Collection
Different Database
Different Collection
ISOLATED
Reference: Considerations on MongoDB multitenancy blog post
Database Multitenancy in Ruby
Database Multitenancy in Ruby
Database Multitenancy in Ruby
Database Multitenancy in Ruby
MONGODB
SETUP TENANT DATABASE
▸ Create Database
▸ Create collections
▸ Shard collections
▸ Define shard keys
▸ Set tagged ranges
▸ Create indices
▸ Seed with initial data
Building on top of Mongoid
Building on top of Mongoid
Building on top of Mongoid
Database Multitenancy in Ruby
PROS AND CONS
PROS
Rack compliant
PROS AND CONS
PROS
Rack compliant
No one needs to care
PROS AND CONS
PROS
Rack compliant
No one needs to care
Isolates multitenancy implementation to a single method
PROS AND CONS
PROS
Rack compliant
No one needs to care
Isolates multitenancy implementation to a single method
If something goes wrong it ensures it goes back to the default
PROS AND CONS
PROS
Rack compliant
No one needs to care
Isolates multitenancy implementation to a single method
If something goes wrong it ensures it goes back to the default
CONS
Always need to define the database for maintenance tasks
PROS AND CONS
PROS
Rack compliant
No one needs to care
Isolates multitenancy implementation to a single method
If something goes wrong it ensures it goes back to the default
CONS
Always need to define the database for maintenance tasks
Need to store the tenant database name somewhere else
PROS AND CONS
PROS
Rack compliant
No one needs to care
Isolates multitenancy implementation to a single method
If something goes wrong it ensures it goes back to the default
CONS
Always need to define the database for maintenance tasks
Need to store the tenant database name somewhere else
You need to be ready to not have the database setup right away
REAL WORLD
ADVANTAGES
▸ Performance not affected by other customers data growth
▸
REAL WORLD
ADVANTAGES
▸ Performance not affected by other customers data growth
▸ Easier to perform data migrations for single customers
REAL WORLD
ADVANTAGES
▸ Performance not affected by other customers data growth
▸ Easier to perform data migrations for single customers
▸ Delete old customers data is a simple DROP DATABASE
REAL WORLD
ADVANTAGES
▸ Performance not affected by other customers data growth
▸ Easier to perform data migrations for single customers
▸ Delete old customers data is a simple DROP DATABASE
GOTCHAS
▸ You are on your own, no support, no one will care about if creating a
database is slow or listing them takes ages (MongoDB Cloud Manager)
REAL WORLD
ADVANTAGES
▸ Performance not affected by other customers data growth
▸ Easier to perform data migrations for single customers
▸ Delete old customers data is a simple DROP DATABASE
GOTCHAS
▸ You are on your own, no support, no one will care about if creating a
database is slow or listing them takes ages (MongoDB Cloud Manager)
▸ Monitoring tools like New Relic discard database information when
showing query performance metrics
YOU CAN JOIN US
WE ARE HIRING
▸ Backend
▸ Frontend
▸ Mobile iOS/Android
TALK TO ME
https://github.com/lqd-io
ME
JOÃO SOARES
@_jasoares
github.com/jasoares
linkedin.com/in/jaisoares
CTO & Cofounder @ Liquid
Previously:
Mobitto
Way2Inov
ASK ME ANYTHING

More Related Content

PDF
Azure document db
PPTX
Introduction to mongo db
PPTX
Couchbase - NoSQL for you! (SDP 2014)
PPTX
Making MySQL Agile-ish
PDF
SQL vs NoSQL, an experiment with MongoDB
PPTX
Digging Into Gutenberg
PDF
MongoDB
PPTX
Advanced Schema Design Patterns
Azure document db
Introduction to mongo db
Couchbase - NoSQL for you! (SDP 2014)
Making MySQL Agile-ish
SQL vs NoSQL, an experiment with MongoDB
Digging Into Gutenberg
MongoDB
Advanced Schema Design Patterns

What's hot (20)

KEY
Using NoSQL MongoDB with ColdFusion
PPTX
A Presentation on MongoDB Introduction - Habilelabs
KEY
Mongo Seattle - The Business of MongoDB
PPS
PDF
ITB2016 - NoSQL with mongodb and ColdFusion (CFML)
PPT
Introduction to mongoDB
PDF
Mongo db
PDF
SQL vs NoSQL | MySQL vs MongoDB Tutorial | Edureka
PPTX
WiredTiger Overview
PPTX
Cosmos db
PDF
MongoDB for Coder Training (Coding Serbia 2013)
KEY
MongoDB Strange Loop 2009
PDF
Sql server 2014 what's new-
PDF
Html5-Web-Storage
PDF
https://docs.google.com/presentation/d/1DcL4zK6i3HZRDD4xTGX1VpSOwyu2xBeWLT6a_...
PDF
Intro To MongoDB
KEY
Discover MongoDB - Israel
PDF
Postgres seminar
PPTX
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
PDF
COSCUP 2019 - The discussion between Knex.js and PostgreSQL
Using NoSQL MongoDB with ColdFusion
A Presentation on MongoDB Introduction - Habilelabs
Mongo Seattle - The Business of MongoDB
ITB2016 - NoSQL with mongodb and ColdFusion (CFML)
Introduction to mongoDB
Mongo db
SQL vs NoSQL | MySQL vs MongoDB Tutorial | Edureka
WiredTiger Overview
Cosmos db
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB Strange Loop 2009
Sql server 2014 what's new-
Html5-Web-Storage
https://docs.google.com/presentation/d/1DcL4zK6i3HZRDD4xTGX1VpSOwyu2xBeWLT6a_...
Intro To MongoDB
Discover MongoDB - Israel
Postgres seminar
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
COSCUP 2019 - The discussion between Knex.js and PostgreSQL
Ad

Similar to Database Multitenancy in Ruby (20)

PDF
MongoDB: Advantages of an Open Source NoSQL Database
PPTX
Multi Tenancy In The Cloud
PPTX
MongoDB Evenings Minneapolis: MongoDB is Cool But When Should I Use It?
PDF
TCO - MongoDB vs. Oracle
PDF
TCO Comparison MongoDB & Oracle
KEY
Deployment Strategy
PDF
How to choose a database
PPTX
MongoDB Evenings Toronto - Monolithic to Microservices with MongoDB
PPTX
MongoDB on Financial Services Sector
PDF
Mongo db transcript
KEY
MongoDB vs Mysql. A devops point of view
PPTX
Cloud brew cloudcamp
KEY
KEY
Deployment Strategies
PDF
MONGODB VS MYSQL: A COMPARATIVE STUDY OF PERFORMANCE IN SUPER MARKET MANAGEME...
PDF
MONGODB VS MYSQL: A COMPARATIVE STUDY OF PERFORMANCE IN SUPER MARKET MANAGEME...
PDF
MONGODB VS MYSQL: A COMPARATIVE STUDY OF PERFORMANCE IN SUPER MARKET MANAGEME...
PPTX
Python Ireland Conference 2016 - Python and MongoDB Workshop
PDF
MongoDB at MapMyFitness
PPT
No SQL and MongoDB - Hyderabad Scalability Meetup
MongoDB: Advantages of an Open Source NoSQL Database
Multi Tenancy In The Cloud
MongoDB Evenings Minneapolis: MongoDB is Cool But When Should I Use It?
TCO - MongoDB vs. Oracle
TCO Comparison MongoDB & Oracle
Deployment Strategy
How to choose a database
MongoDB Evenings Toronto - Monolithic to Microservices with MongoDB
MongoDB on Financial Services Sector
Mongo db transcript
MongoDB vs Mysql. A devops point of view
Cloud brew cloudcamp
Deployment Strategies
MONGODB VS MYSQL: A COMPARATIVE STUDY OF PERFORMANCE IN SUPER MARKET MANAGEME...
MONGODB VS MYSQL: A COMPARATIVE STUDY OF PERFORMANCE IN SUPER MARKET MANAGEME...
MONGODB VS MYSQL: A COMPARATIVE STUDY OF PERFORMANCE IN SUPER MARKET MANAGEME...
Python Ireland Conference 2016 - Python and MongoDB Workshop
MongoDB at MapMyFitness
No SQL and MongoDB - Hyderabad Scalability Meetup
Ad

Recently uploaded (20)

PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Cloud computing and distributed systems.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Modernizing your data center with Dell and AMD
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
NewMind AI Monthly Chronicles - July 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Unlocking AI with Model Context Protocol (MCP)
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Cloud computing and distributed systems.
Mobile App Security Testing_ A Comprehensive Guide.pdf
Big Data Technologies - Introduction.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The AUB Centre for AI in Media Proposal.docx
MYSQL Presentation for SQL database connectivity
Understanding_Digital_Forensics_Presentation.pptx
Modernizing your data center with Dell and AMD
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy

Database Multitenancy in Ruby

  • 2. TYPICAL MULTITENANCY OPTIONS SQL WORLD SHARED Same Database Different Schema ISOLATED
  • 3. TYPICAL MULTITENANCY OPTIONS SQL WORLD SHARED Same Database Different Schema Different Database Same Schema ISOLATED
  • 4. TYPICAL MULTITENANCY OPTIONS SQL WORLD SHARED Same Database Different Schema Different Database Same Schema Different Database Different Schema ISOLATED
  • 5. TYPICAL MULTITENANCY OPTIONS SQL WORLD SCHEMA-LESS WORLD - MONGODB SHARED Same Database Different Schema Different Database Same Schema Different Database Different Schema ISOLATED SHARED Same Database Different Collection ISOLATED
  • 6. TYPICAL MULTITENANCY OPTIONS SQL WORLD SCHEMA-LESS WORLD - MONGODB SHARED Same Database Different Schema Different Database Same Schema Different Database Different Schema ISOLATED SHARED Same Database Different Collection Different Database Different Collection ISOLATED Reference: Considerations on MongoDB multitenancy blog post
  • 11. MONGODB SETUP TENANT DATABASE ▸ Create Database ▸ Create collections ▸ Shard collections ▸ Define shard keys ▸ Set tagged ranges ▸ Create indices ▸ Seed with initial data
  • 12. Building on top of Mongoid
  • 13. Building on top of Mongoid
  • 14. Building on top of Mongoid
  • 17. PROS AND CONS PROS Rack compliant No one needs to care
  • 18. PROS AND CONS PROS Rack compliant No one needs to care Isolates multitenancy implementation to a single method
  • 19. PROS AND CONS PROS Rack compliant No one needs to care Isolates multitenancy implementation to a single method If something goes wrong it ensures it goes back to the default
  • 20. PROS AND CONS PROS Rack compliant No one needs to care Isolates multitenancy implementation to a single method If something goes wrong it ensures it goes back to the default CONS Always need to define the database for maintenance tasks
  • 21. PROS AND CONS PROS Rack compliant No one needs to care Isolates multitenancy implementation to a single method If something goes wrong it ensures it goes back to the default CONS Always need to define the database for maintenance tasks Need to store the tenant database name somewhere else
  • 22. PROS AND CONS PROS Rack compliant No one needs to care Isolates multitenancy implementation to a single method If something goes wrong it ensures it goes back to the default CONS Always need to define the database for maintenance tasks Need to store the tenant database name somewhere else You need to be ready to not have the database setup right away
  • 23. REAL WORLD ADVANTAGES ▸ Performance not affected by other customers data growth ▸
  • 24. REAL WORLD ADVANTAGES ▸ Performance not affected by other customers data growth ▸ Easier to perform data migrations for single customers
  • 25. REAL WORLD ADVANTAGES ▸ Performance not affected by other customers data growth ▸ Easier to perform data migrations for single customers ▸ Delete old customers data is a simple DROP DATABASE
  • 26. REAL WORLD ADVANTAGES ▸ Performance not affected by other customers data growth ▸ Easier to perform data migrations for single customers ▸ Delete old customers data is a simple DROP DATABASE GOTCHAS ▸ You are on your own, no support, no one will care about if creating a database is slow or listing them takes ages (MongoDB Cloud Manager)
  • 27. REAL WORLD ADVANTAGES ▸ Performance not affected by other customers data growth ▸ Easier to perform data migrations for single customers ▸ Delete old customers data is a simple DROP DATABASE GOTCHAS ▸ You are on your own, no support, no one will care about if creating a database is slow or listing them takes ages (MongoDB Cloud Manager) ▸ Monitoring tools like New Relic discard database information when showing query performance metrics
  • 28. YOU CAN JOIN US WE ARE HIRING ▸ Backend ▸ Frontend ▸ Mobile iOS/Android TALK TO ME https://github.com/lqd-io