Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rails Pacific - Multitenancy with Rails
Search
Ryan Bigg
October 25, 2014
Programming
0
240
Rails Pacific - Multitenancy with Rails
Covers the lessons learned about Multitenancy with Rails in the process of writing my book.
Ryan Bigg
October 25, 2014
Tweet
Share
More Decks by Ryan Bigg
See All by Ryan Bigg
Hiring Juniors - RubyConf Indonesia 2019 Closing Keynote
radar
1
370
Web Directions - Code Leaders - Hiring Juniors
radar
0
520
The Future of Rails - Take 2
radar
0
96
The Future of Rails
radar
1
100
Exploding Rails
radar
9
1.8k
Hiring Juniors
radar
2
410
The Perfect Coding Test
radar
0
110
Your First Developer Job
radar
1
100
Hiring Juniors
radar
2
270
Other Decks in Programming
See All in Programming
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
fs2-io を試してたらバグを見つけて直した話
chencmd
0
230
テストコード文化を0から作り、変化し続けた組織
kazatohiei
2
1.5k
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
CSC305 Lecture 26
javiergs
PRO
0
140
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
120
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
300
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Rails Girls Zürich Keynote
gr2m
94
13k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Transcript
lifx.co
#21 Not #21
Multitenancy with Rails Ryan Bigg
None
None
Multitenancy?
None
None
None
Organization Team Repos
User Repos
None
…
DOGLIFEBETA! Garçon Fluffy Brutus “Like Facebook, but for dogs”
Multitenancy with Rails?
None
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
None
Thread.current Thread.current
apartment ✔ well documented ✔ well maintained ✔ clean code
“If you are using PostgreSQL, Apartment by default will set
up a new schema and migrate into there.”
“If you are using PostgreSQL, Apartment by default will set
up a new schema and migrate into there.”
None
“A database contains one or more named schemas, which in
turn contain tables.” “There are several reasons why one might want to use schemas: * To allow many users to use one database without interfering with each other.”
“To allow many users to use one database without interfering
with each other.”
ryanbigg=# SHOW search_path; search_path ---------------- "$user",public (1 row) "$user",public
fluffy.doglife.com garcon.doglife.com DOGLIFE BETA! brutus.doglife.com 1 2 3
(1.4ms) CREATE SCHEMA "garcon" <more tables go here>
None
None
None
DEPLOY IT!
Heroku Postgres
Backup time 24 hours
PostgreSQL is great
PostgreSQL with too many schemas
Part 2: Schema-less Multitenancy
Apartment
None
TEST ALL THE TIME
TEST ALL THE TIME?
TEST ALL THE TIME
Are you testing right now? No?
TEST ALL THE TIME OR ELSE
A codebase without tests
fluffy.doglife.com Fluffy’s Posts current_account = Fluffy @posts = current_account.posts fluffy.doglife.com/posts
Feature #1: Viewing Posts
A guest on Account A’s subdomain should only see Account
A’s posts Expected to not see “<Account B’s post>” Feature #1: Viewing Posts
Feature #1: Viewing Posts
Feature #1: Viewing Posts
Feature #1: Viewing Posts
A guest on Account A’s subdomain should only see Account
A’s posts Feature #1: Viewing Posts
fluffy.doglife.com Fluffy’s Posts current_account = Fluffy @posts = current_account.posts fluffy.doglife.com/posts
Feature #1: Viewing Posts
fluffy.doglife.com Fluffy’s Albums current_account = Fluffy @albums = current_account.albums fluffy.doglife.com/albums
Fluffy’s First Birthday Pictures @pictures = @album.pictures fluffy.doglife.com/albums/1/pictures Feature #2: Viewing Pictures
A guest on Account A’s subdomain should only see Account
A’s albums Expected to not see “<Account B’s album>” Feature #2: Viewing Pictures
Feature #2: Viewing Pictures
Feature #2: Viewing Pictures
A guest on Account A’s subdomain should only see Account
A’s albums Feature #2: Viewing Pictures
A guest on Account A’s subdomain viewing an album shows
pictures from that album Expected to not see “<Account B’s picture>” Feature #2: Viewing Pictures
Feature #2: Viewing Pictures
Feature #2: Viewing Pictures
A guest on Account A’s subdomain viewing an album shows
pictures from that album Feature #2: Viewing Pictures
fluffy.doglife.com Fluffy’s Albums current_account = Fluffy @albums = current_account.albums fluffy.doglife.com/albums
Fluffy’s First Birthday Pictures @pictures = @album.pictures fluffy.doglife.com/albums/1/pictures Feature #2: Viewing Pictures
Feature #2: Viewing Pictures
REGRESSION TEST ALL THE TIME
Feature #2: Viewing Pictures
None
Part 3: Subscriptions
None
doglife.com/sign_up plan = Basic ($9.99) Feature #3: User subscribes to
a plan ???
“Writing code to manage subscriptions is easy.” - nobody, ever
Your subscriptions code
PayPal
None
PayPal
None
“Stripe makes recurring and subscription-based billing easy.”
None
None
None
:CreateRecurringPaymentsProfileRequestDetails PayPal
None
“My company makes your life easy.”
doglife.com/sign_up plan = Basic ($9.99) Feature #3: User subscribes to
a plan
None
[email protected]
[email protected]
⁉
[email protected]
leanpub.com/multi-tenancy-rails/c/railspacific $10 off