Covers the lessons learned about Multitenancy with Rails in the process of writing my book.
lifx.co
View Slide
#21Not #21
Multitenancywith RailsRyan Bigg
Multitenancy?
OrganizationTeamRepos
UserRepos
…
DOGLIFEBETA!Garçon Fluffy Brutus“Like Facebook, but for dogs”
Multitenancywith Rails?
Is it…✔ well maintained✔ well documented✔ clean code
acts_as_tenant✔ well documented
acts_as_tenant✔ well maintained✔ 140 commits, 19 contributors, low issue count✔ CI on Travis
acts_as_tenant✔ clean code
acts_as_tenant
RequestStore.store
Thread.currentThread.current
apartment✔ well documented✔ well maintained✔ clean code
“If you are using PostgreSQL, Apartmentby default will set up a new schema andmigrate into there.”
“If you are usingPostgreSQL, Apartmentby default will set up a newschema andmigrate into there.”
“A database contains one or morenamed schemas, which in turncontain tables.”“There are several reasons why onemight want to use schemas:* To allow many users to use onedatabase without interfering witheach other.”
“To allow many usersto use one databasewithout interferingwith each other.”
ryanbigg=# SHOW search_path;search_path----------------"$user",public(1 row)"$user",public
fluffy.doglife.comgarcon.doglife.comDOGLIFE BETA!brutus.doglife.com123
(1.4ms) CREATE SCHEMA "garcon"
DEPLOY IT!
Heroku Postgres
Backup time24 hours
PostgreSQLis great
PostgreSQL with too many schemas
Part 2:Schema-lessMultitenancy
Apartment
TEST ALL THE TIME
TEST ALL THE TIME?
TEST ALLTHE TIME
Are you testing right now?No?
TEST ALLTHE TIMEOR ELSE
A codebase without tests
fluffy.doglife.comFluffy’s Postscurrent_account = Fluffy@posts = current_account.postsfluffy.doglife.com/postsFeature #1: Viewing Posts
A gueston Account A’s subdomainshould only see Account A’s postsExpected to not see “”Feature #1: Viewing Posts
Feature #1: Viewing Posts
A gueston Account A’s subdomainshould only see Account A’s postsFeature #1: Viewing Posts
fluffy.doglife.comFluffy’s Albumscurrent_account = Fluffy@albums = current_account.albumsfluffy.doglife.com/albumsFluffy’s First Birthday Pictures@pictures = @album.picturesfluffy.doglife.com/albums/1/picturesFeature #2: Viewing Pictures
A gueston Account A’s subdomainshould only see Account A’s albumsExpected to not see “”Feature #2: Viewing Pictures
Feature #2: Viewing Pictures
A gueston Account A’s subdomainshould only see Account A’s albumsFeature #2: Viewing Pictures
A gueston Account A’s subdomainviewing an albumshows pictures from that albumExpected to not see “”Feature #2: Viewing Pictures
A gueston Account A’s subdomainviewing an albumshows pictures from that albumFeature #2: Viewing Pictures
REGRESSIONTEST ALL THETIME
Part 3:Subscriptions
doglife.com/sign_upplan = Basic ($9.99)Feature #3: User subscribes to a plan???
“Writing code to managesubscriptions is easy.”- nobody, ever
Your subscriptions code
PayPal
“Stripe makesrecurring andsubscription-basedbilling easy.”
:CreateRecurringPaymentsProfileRequestDetailsPayPal
“My companymakes your lifeeasy.”
doglife.com/sign_upplan = Basic ($9.99)Feature #3: User subscribes to a plan
[email protected][email protected]⁉ [email protected]
leanpub.com/multi-tenancy-rails/c/railspacific$10 off