Slide 1

Slide 1 text

lifx.co

Slide 2

Slide 2 text

#21 Not #21

Slide 3

Slide 3 text

Multitenancy with Rails Ryan Bigg

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Multitenancy?

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Organization Team Repos

Slide 11

Slide 11 text

User Repos

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Slide 14

Slide 14 text

DOGLIFEBETA! Garçon Fluffy Brutus “Like Facebook, but for dogs”

Slide 15

Slide 15 text

Multitenancy with Rails?

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Is it… ✔ well maintained ✔ well documented ✔ clean code

Slide 18

Slide 18 text

acts_as_tenant ✔ well documented

Slide 19

Slide 19 text

acts_as_tenant ✔ well maintained ✔ 140 commits, 19 contributors, low issue count ✔ CI on Travis

Slide 20

Slide 20 text

acts_as_tenant ✔ clean code

Slide 21

Slide 21 text

acts_as_tenant

Slide 22

Slide 22 text

RequestStore.store

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Thread.current Thread.current

Slide 25

Slide 25 text

apartment ✔ well documented ✔ well maintained ✔ clean code

Slide 26

Slide 26 text

“If you are using PostgreSQL, Apartment by default will set up a new schema and migrate into there.”

Slide 27

Slide 27 text

“If you are using PostgreSQL, Apartment by default will set up a new schema and migrate into there.”

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

“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.”

Slide 30

Slide 30 text

“To allow many users to use one database without interfering with each other.”

Slide 31

Slide 31 text

ryanbigg=# SHOW search_path; search_path ---------------- "$user",public (1 row) "$user",public

Slide 32

Slide 32 text

fluffy.doglife.com garcon.doglife.com DOGLIFE BETA! brutus.doglife.com 1 2 3

Slide 33

Slide 33 text

(1.4ms) CREATE SCHEMA "garcon"

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

DEPLOY IT!

Slide 38

Slide 38 text

Heroku Postgres

Slide 39

Slide 39 text

Backup time 24 hours

Slide 40

Slide 40 text

PostgreSQL is great

Slide 41

Slide 41 text

PostgreSQL with too many schemas

Slide 42

Slide 42 text

Part 2: Schema-less Multitenancy

Slide 43

Slide 43 text

Apartment

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

TEST ALL THE TIME

Slide 46

Slide 46 text

TEST ALL THE TIME?

Slide 47

Slide 47 text

TEST ALL THE TIME

Slide 48

Slide 48 text

Are you testing right now? No?

Slide 49

Slide 49 text

TEST ALL THE TIME OR ELSE

Slide 50

Slide 50 text

A codebase without tests

Slide 51

Slide 51 text

fluffy.doglife.com Fluffy’s Posts current_account = Fluffy @posts = current_account.posts fluffy.doglife.com/posts Feature #1: Viewing Posts

Slide 52

Slide 52 text

A guest on Account A’s subdomain should only see Account A’s posts Expected to not see “” Feature #1: Viewing Posts

Slide 53

Slide 53 text

Feature #1: Viewing Posts

Slide 54

Slide 54 text

Feature #1: Viewing Posts

Slide 55

Slide 55 text

Feature #1: Viewing Posts

Slide 56

Slide 56 text

A guest on Account A’s subdomain should only see Account A’s posts Feature #1: Viewing Posts

Slide 57

Slide 57 text

fluffy.doglife.com Fluffy’s Posts current_account = Fluffy @posts = current_account.posts fluffy.doglife.com/posts Feature #1: Viewing Posts

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

A guest on Account A’s subdomain should only see Account A’s albums Expected to not see “” Feature #2: Viewing Pictures

Slide 60

Slide 60 text

Feature #2: Viewing Pictures

Slide 61

Slide 61 text

Feature #2: Viewing Pictures

Slide 62

Slide 62 text

A guest on Account A’s subdomain should only see Account A’s albums Feature #2: Viewing Pictures

Slide 63

Slide 63 text

A guest on Account A’s subdomain viewing an album shows pictures from that album Expected to not see “” Feature #2: Viewing Pictures

Slide 64

Slide 64 text

Feature #2: Viewing Pictures

Slide 65

Slide 65 text

Feature #2: Viewing Pictures

Slide 66

Slide 66 text

A guest on Account A’s subdomain viewing an album shows pictures from that album Feature #2: Viewing Pictures

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

Feature #2: Viewing Pictures

Slide 69

Slide 69 text

REGRESSION TEST ALL THE TIME

Slide 70

Slide 70 text

Feature #2: Viewing Pictures

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

Part 3: Subscriptions

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

doglife.com/sign_up plan = Basic ($9.99) Feature #3: User subscribes to a plan ???

Slide 75

Slide 75 text

“Writing code to manage subscriptions is easy.” - nobody, ever

Slide 76

Slide 76 text

Your subscriptions code

Slide 77

Slide 77 text

PayPal

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

PayPal

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

“Stripe makes recurring and subscription-based billing easy.”

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

:CreateRecurringPaymentsProfileRequestDetails PayPal

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

“My company makes your life easy.”

Slide 88

Slide 88 text

doglife.com/sign_up plan = Basic ($9.99) Feature #3: User subscribes to a plan

Slide 89

Slide 89 text

No content

Slide 91

Slide 91 text

leanpub.com/multi-tenancy-rails/c/railspacific $10 off