Hi Guys
Need guidance to know how to design / develop the Django multi-tenant application. We are using Python, and SQL lite database, but willing to use PostgreSQL or mySQL database if required.
Following is the scenario.
1- We have got the domain application.testcom
1- Users use their own application url i.e. user1.applicaiton.testcom , user2.application.testcom , user3.application.testcom
2- We need to keep the data specific to the user1, user2 and user3 etc
3- once the user login to the application, the login page should show the logo and application name specific to the users e.g. “User1 App”, “User2 App”, “User3 App”
4- We are using one database schema for application and want to use the application logic to achieve the above.
5- Do we need to create separate database schema for each user like user1_db_schema, user2_db_schema, user3_db_schema to achieve the above 3 points?
Thanks in advance 
Hello there.
You have a few options, actually there are several approaches for this kind of problem.
If you want all the work done for you for routing based on the domain, then django-tenants is the answer you’re looking for. Key notes about it:
- Tenant data are separated by schemas (I think it only works on PSQL) and each tenant has it’s own schema. This come with a few drawbacks though, specially migrations, I’ve worked on a few projects and the migrations can take from minutes to hours to complete, depending on the number of tenants you have.
- It uses a subdomain to route the data to a specific tenant., and set the schema accordingly.
If you want a bit more control over the solution, and all data on a single database and schema, you can use django-multitenant, it doesn’t had a release in a few years, but it’s quite stable. I’ve been using for the last few years, and it’s a setup and forget, doesn’t cause any issues. We need to create a few wrappers around some of the functions to get the behavior we wanted for a tenant hierarchy. You won’t have all the routing done for you, you’ll need to it yourself, but you’ll find that the code for this is quite straight-forward, you can find some inspiration from the django-tenants middlewares on how to do that. The experience moving from django-tenants to django-multitenant was amazing, didn’t have any problems with the database since. And if you project scale to the moon, you can shard you database with their solution (never needed that). Right now we’re running a project with about 1k users and tenants.
There are probably a few other options that you might want to consider, based on your use case. I can’t provide such advice on these others, since I didn’t use them.
I hope you find this useful.
Hi,
I’m having the same issue. In my case, i’m thinking about using multiple SQLite databases and use a database router for each tenant. This is a viable option, but probably not the most efficient one. The biggest win here, is that the migrations can be easier and totally isolated by tenant and you can make it in canary way if you want (but it can difficult), and as the database is just a SQLite file replication is easy enough. I see that SQLite is more than enough for the vast majority of use cases.