Database Multitenancy in Ruby

30
DATABASE MULTITENANCY RUBY IDIOM CASE

Transcript of Database Multitenancy in Ruby

Page 1: Database Multitenancy in Ruby

DATABASE MULTITENANCY

RUBY IDIOM CASE

Page 2: Database Multitenancy in Ruby

TYPICAL MULTITENANCY OPTIONS

SQL WORLD

SHAREDSame Database

Different SchemaISOLATED

Page 3: Database Multitenancy in Ruby

TYPICAL MULTITENANCY OPTIONS

SQL WORLD

SHAREDSame Database

Different Schema

Different Database

Same SchemaISOLATED

Page 4: Database Multitenancy in Ruby

TYPICAL MULTITENANCY OPTIONS

SQL WORLD

SHAREDSame Database

Different Schema

Different Database

Same Schema

Different Database

Different SchemaISOLATED

Page 5: Database Multitenancy in Ruby

TYPICAL MULTITENANCY OPTIONS

SQL WORLD

SCHEMA-LESS WORLD - MONGODB

SHAREDSame Database

Different Schema

Different Database

Same Schema

Different Database

Different SchemaISOLATED

SHAREDSame Database

Different CollectionISOLATED

Page 6: Database Multitenancy in Ruby

TYPICAL MULTITENANCY OPTIONS

SQL WORLD

SCHEMA-LESS WORLD - MONGODB

SHAREDSame Database

Different Schema

Different Database

Same Schema

Different Database

Different SchemaISOLATED

SHAREDSame Database

Different Collection

Different Database

Different CollectionISOLATED

Reference: Considerations on MongoDB multitenancy blog post

Page 7: Database Multitenancy in Ruby
Page 8: Database Multitenancy in Ruby
Page 9: Database Multitenancy in Ruby
Page 10: Database Multitenancy in Ruby
Page 11: 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

Page 12: Database Multitenancy in Ruby

Building on top of Mongoid

Page 13: Database Multitenancy in Ruby

Building on top of Mongoid

Page 14: Database Multitenancy in Ruby

Building on top of Mongoid

Page 15: Database Multitenancy in Ruby
Page 16: Database Multitenancy in Ruby

PROS AND CONSPROS

Rack compliant

Page 17: Database Multitenancy in Ruby

PROS AND CONSPROS

Rack compliant

No one needs to care

Page 18: Database Multitenancy in Ruby

PROS AND CONSPROS

Rack compliant

No one needs to care

Isolates multitenancy implementation to a single method

Page 19: Database Multitenancy in Ruby

PROS AND CONSPROS

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

Page 20: Database Multitenancy in Ruby

PROS AND CONSPROS

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

Page 21: Database Multitenancy in Ruby

PROS AND CONSPROS

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

Page 22: Database Multitenancy in Ruby

PROS AND CONSPROS

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

Page 23: Database Multitenancy in Ruby

REAL WORLD

ADVANTAGES

▸ Performance not affected by other customers data growth

Page 24: Database Multitenancy in Ruby

REAL WORLD

ADVANTAGES

▸ Performance not affected by other customers data growth

▸ Easier to perform data migrations for single customers

Page 25: Database Multitenancy in Ruby

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

Page 26: Database Multitenancy in Ruby

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)

Page 27: Database Multitenancy in Ruby

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

Page 28: Database Multitenancy in Ruby

YOU CAN JOIN US

WE ARE HIRING

▸ Backend

▸ Frontend

▸ Mobile iOS/Android

TALK TO ME

https://github.com/lqd-io

Page 29: Database Multitenancy in Ruby

ME

JOÃO SOARES

@_jasoares

github.com/jasoares

linkedin.com/in/jaisoares

CTO & Cofounder @ Liquid

Previously:

Mobitto

Way2Inov

Page 30: Database Multitenancy in Ruby

ASK ME ANYTHING