Top Banner
40

Multi tenancy with PostgreSQL

Nov 11, 2014

Download

Documents

ramontayag

Watch the talk at http://www.youtube.com/watch?v=XuQfXQYUsgY&feature=share&list=PL0mVjsUoElSE4GBZEiogUeJLyvgzdb1N7
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Multi tenancy with PostgreSQL
Page 2: Multi tenancy with PostgreSQL

Multi-tenancywith PostgreSQL

Page 3: Multi tenancy with PostgreSQL

Requirements

Page 4: Multi tenancy with PostgreSQL
Page 5: Multi tenancy with PostgreSQL
Page 6: Multi tenancy with PostgreSQL
Page 7: Multi tenancy with PostgreSQL
Page 8: Multi tenancy with PostgreSQL
Page 9: Multi tenancy with PostgreSQL
Page 10: Multi tenancy with PostgreSQL

Three waysbit.ly/msn-multitenant-arch

Page 11: Multi tenancy with PostgreSQL

Shared Database, Shared Namespace

Page 12: Multi tenancy with PostgreSQL

Separate Databases

Page 13: Multi tenancy with PostgreSQL

Shared Database,Separate Namespace

Page 14: Multi tenancy with PostgreSQL

hasschemas

Page 15: Multi tenancy with PostgreSQL

hasnamespaces

Page 16: Multi tenancy with PostgreSQL

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

Page 17: Multi tenancy with PostgreSQL

App

Page 18: Multi tenancy with PostgreSQL
Page 19: Multi tenancy with PostgreSQL

carding.app.com/products/1-grapes

Page 20: Multi tenancy with PostgreSQL

SET SEARCH_PATH = 'carding'

Page 21: Multi tenancy with PostgreSQL

'carding'

SELECT * FROM products where id = 1;

Page 22: Multi tenancy with PostgreSQL

Common Tables

Page 23: Multi tenancy with PostgreSQL

"public"

Page 24: Multi tenancy with PostgreSQL

'carding'

SELECT * FROM public.invoices where tenant_id = 1;

Page 25: Multi tenancy with PostgreSQL

Apartmentgithub.com/bradrobertson/apartment

Page 26: Multi tenancy with PostgreSQL
Page 27: Multi tenancy with PostgreSQL
Page 28: Multi tenancy with PostgreSQL

bob.sql

carding

alice.sql

Page 29: Multi tenancy with PostgreSQL

carding

Page 30: Multi tenancy with PostgreSQL

carding assimo

Page 31: Multi tenancy with PostgreSQL

assimo

Page 32: Multi tenancy with PostgreSQL

Storeygithub.com/ramontayag/storey

Page 33: Multi tenancy with PostgreSQL

Gotchas

Page 34: Multi tenancy with PostgreSQL

Problem: Testing

● transactions do not play well with schemas

Page 35: Multi tenancy with PostgreSQL

Answer: Testing

● in tests, treat the public schema as a tenant

Page 36: Multi tenancy with PostgreSQL

Problem: Migrations

● migrate every schema

Page 37: Multi tenancy with PostgreSQL

Answer: Apartment/Storey

● loops through the namespaces and migrates each one

Page 38: Multi tenancy with PostgreSQL

Problem: Background Jobs

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

Page 39: Multi tenancy with PostgreSQL

Answer: Pass schema name

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

Page 40: Multi tenancy with PostgreSQL

Questions?