Multi-tenant Django w/ Multi-DB?

325 views
Skip to first unread message

Marco Louro

unread,
Jan 5, 2011, 6:35:17 AM1/5/11
to Django users
Hey,

I'm wondering if Multi-DB supports some kind of multi-tenancy on the
DB level (one app instance supporting multiple databases - one per
client - 2 on http://www.ibm.com/developerworks/cloud/library/cl-multitenantsaas/figure0.gif).
I don't think it does, but just want to be sure.

I'm thinking that each database would be named after the subdomain,
but storing every DB in settings.py is not an ideal solution for this.


Thanks

Justin

unread,
Jan 5, 2011, 7:30:39 AM1/5/11
to Django users
Have you looked at the Sites framework? You could have multiple
tenants using one database and use a ForeingKey to a Site object to
structure the data. This will result in more complex queries, but
might be less of a cost than the maintenance issues (see below).

If you continue reading that IBM document, the "Database
Considerations" section strongly urges you not to pursue the multiple-
tenants, multiple-databases model due to the inherent maintenance
overhead.

http://www.ibm.com/developerworks/cloud/library/cl-multitenantsaas/#N10210

If you end up finding a good solution to this hairy problem, please
post it. I'd be interested to see what you come up with.

-Justin

Marco Louro

unread,
Jan 5, 2011, 8:52:36 AM1/5/11
to Django users
Thanks for your reply Justin,

I'd like to avoid having multiple tenants in the same database, I feel
multi-database is easier to scale, and simpler in a code maintenance
sense. It does required to run database migrations once per tenant,
but I still see it as the better solution.

One solution I saw is having a schema per tenant:
http://tidbids.posterous.com/saas-with-django-and-postgresql-schemas
and another is a pandora's box:
https://github.com/gregmuellegger/django-pandora

I haven't tried any of these, but they seem like they might be
solutions for this problem.


On Jan 5, 12:30 pm, Justin <jlmurph...@gmail.com> wrote:
> Have you looked at the Sites framework? You could have multiple
> tenants using one database and use a ForeingKey to a Site object to
> structure the data. This will result in more complex queries, but
> might be less of a cost than the maintenance issues (see below).
>
> If you continue reading that IBM document, the "Database
> Considerations" section strongly urges you not to pursue the multiple-
> tenants, multiple-databases model due to the inherent maintenance
> overhead.
>
> http://www.ibm.com/developerworks/cloud/library/cl-multitenantsaas/#N...
Reply all
Reply to author
Forward
0 new messages