multi tenancy with postgresql

40

Upload: ramontayag

Post on 11-Nov-2014

5.403 views

Category:

Documents


3 download

DESCRIPTION

Watch the talk at http://www.youtube.com/watch?v=XuQfXQYUsgY&feature=share&list=PL0mVjsUoElSE4GBZEiogUeJLyvgzdb1N7

TRANSCRIPT

Multi-tenancywith PostgreSQL

Requirements

Three waysbit.ly/msn-multitenant-arch

Shared Database, Shared Namespace

Separate Databases

Shared Database,Separate Namespace

hasschemas

hasnamespaces

Guy Naor on Multi-tenancyhttp://bit.ly/guy-naor-multitenant-2009

App

carding.app.com/products/1-grapes

SET SEARCH_PATH = 'carding'

'carding'

SELECT * FROM products where id = 1;

Common Tables

"public"

'carding'

SELECT * FROM public.invoices where tenant_id = 1;

Apartmentgithub.com/bradrobertson/apartment

bob.sql

carding

alice.sql

carding

carding assimo

assimo

Storeygithub.com/ramontayag/storey

Gotchas

Problem: Testing

● transactions do not play well with schemas

Answer: Testing

● in tests, treat the public schema as a tenant

Problem: Migrations

● migrate every schema

Answer: Apartment/Storey

● loops through the namespaces and migrates each one

Problem: Background Jobs

● how do the workers know which schema contains the data?

Answer: Pass schema name

● Pass the schema name along with the rest of the job arguments

Questions?