Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Scaling Multi-tenant Applications Using
Django And Postgres
Sai Srirampur
August 2018
About Me
•Sai Srirampur a.k.a Sai
•Early engineer @ Citus Data
•Citus: Open source extension which horizontally scales Pos...
Multi-tenant Applications
• Multiple customers each dealing with their own data
• Most SaaS applications are multi-tenant
...
Starting out: 1 tenant per database/schema
• Scales up to 10s to 100s of tenants
• Guarantees better isolation
• At scales...
1000+ tenants: Shared Tables
•Scales to 100,000+ tenants
•Faster running migrations
•Better performance
•But
Make sure ORM...
django_multitenant to the rescue!
“Automates all ORM calls to be scoped to a single tenant.”
Today...
class Purchase(Model):
store = models.ForeignKey(Store)
tenant_id='store_id'
product_purchased = ForeignKey(Produ...
With django_multitenant
class Purchase(TenantModel):
store = models.ForeignKey(Store)
tenant_id='store_id'
product_purchas...
Benefits of django_multitenant
• Minimizes application changes
• Guarantees isolation
• Ready to scale with distributed Po...
Scale out Django!
github.com/citusdata/django-multitenant
www.citusdata.com @citusdata
© 2018 Citus Data. All right reserv...
Upcoming SlideShare
Loading in …5
×

of

Scaling Multi-Tenant Applications Using Django and Postgres | PyBay 2018 | Sai Srirampur Slide 1 Scaling Multi-Tenant Applications Using Django and Postgres | PyBay 2018 | Sai Srirampur Slide 2 Scaling Multi-Tenant Applications Using Django and Postgres | PyBay 2018 | Sai Srirampur Slide 3 Scaling Multi-Tenant Applications Using Django and Postgres | PyBay 2018 | Sai Srirampur Slide 4 Scaling Multi-Tenant Applications Using Django and Postgres | PyBay 2018 | Sai Srirampur Slide 5 Scaling Multi-Tenant Applications Using Django and Postgres | PyBay 2018 | Sai Srirampur Slide 6 Scaling Multi-Tenant Applications Using Django and Postgres | PyBay 2018 | Sai Srirampur Slide 7 Scaling Multi-Tenant Applications Using Django and Postgres | PyBay 2018 | Sai Srirampur Slide 8 Scaling Multi-Tenant Applications Using Django and Postgres | PyBay 2018 | Sai Srirampur Slide 9 Scaling Multi-Tenant Applications Using Django and Postgres | PyBay 2018 | Sai Srirampur Slide 10
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

1 Like

Share

Download to read offline

Scaling Multi-Tenant Applications Using Django and Postgres | PyBay 2018 | Sai Srirampur

Download to read offline

There are a number of data architectures you could use when building a multi-tenant app. Some, such as using one database per customer or one schema per customer. These two options scale to an extent when you have say 10s of tenants. However as you start scaling to hundreds and thousands of tenants, you start running into challenges both from performance and maintenance of tenants perspective.

You could solve the above problem by adding the notion of tenancy directly into the logic of your SaaS application. How to implement/automate this in Django-ORM is a challenge? We will talk about how to make the django-app tenant aware and at a broader level explain how scale out applications that are built on top of Django ORM and follow a multi tenant data model. We'd take postgres as our database of choice and the logic/implementation can be extended to any other relational databases as well.

Related Books

Free with a 30 day trial from Scribd

See all

Scaling Multi-Tenant Applications Using Django and Postgres | PyBay 2018 | Sai Srirampur

  1. 1. Scaling Multi-tenant Applications Using Django And Postgres Sai Srirampur August 2018
  2. 2. About Me •Sai Srirampur a.k.a Sai •Early engineer @ Citus Data •Citus: Open source extension which horizontally scales Postgres •Fun fact: ping pong!
  3. 3. Multi-tenant Applications • Multiple customers each dealing with their own data • Most SaaS applications are multi-tenant • Ex: Shopify, Salesforce etc.
  4. 4. Starting out: 1 tenant per database/schema • Scales up to 10s to 100s of tenants • Guarantees better isolation • At scales of 1k to 100k tenants: •Hard to manage - ex. consistent schema-changes •Long time to run migration •Performance issues
  5. 5. 1000+ tenants: Shared Tables •Scales to 100,000+ tenants •Faster running migrations •Better performance •But Make sure ORM calls are always scoped to a single tenant!
  6. 6. django_multitenant to the rescue! “Automates all ORM calls to be scoped to a single tenant.”
  7. 7. Today... class Purchase(Model): store = models.ForeignKey(Store) tenant_id='store_id' product_purchased = ForeignKey(Product) Purchase.objects.filter(id=1) <=> “SELECT* from purchase where id=1” .
  8. 8. With django_multitenant class Purchase(TenantModel): store = models.ForeignKey(Store) tenant_id='store_id' product_purchased = TenantForeignKey(Product) Purchase.objects.filter(id=1) <=> “SELECT* from purchase where id=1 and store_id=<current_tenant>”
  9. 9. Benefits of django_multitenant • Minimizes application changes • Guarantees isolation • Ready to scale with distributed Postgres (Citus)
  10. 10. Scale out Django! github.com/citusdata/django-multitenant www.citusdata.com @citusdata © 2018 Citus Data. All right reserved. sai@citusdata.com
  • NajmulHoqueSharif

    Nov. 22, 2020

There are a number of data architectures you could use when building a multi-tenant app. Some, such as using one database per customer or one schema per customer. These two options scale to an extent when you have say 10s of tenants. However as you start scaling to hundreds and thousands of tenants, you start running into challenges both from performance and maintenance of tenants perspective. You could solve the above problem by adding the notion of tenancy directly into the logic of your SaaS application. How to implement/automate this in Django-ORM is a challenge? We will talk about how to make the django-app tenant aware and at a broader level explain how scale out applications that are built on top of Django ORM and follow a multi tenant data model. We'd take postgres as our database of choice and the logic/implementation can be extended to any other relational databases as well.

Views

Total views

767

On Slideshare

0

From embeds

0

Number of embeds

10

Actions

Downloads

1

Shares

0

Comments

0

Likes

1

×