Multi-tenant SAAS in Django

Cheruiyot Felix picture Cheruiyot Felix · Feb 14, 2014 · Viewed 9.8k times · Source

I have developed Multi-tenant SAAS apps in PHP/Laravel but recently I had a challenge to develop one in Django/Python. I am still learning Django though and I really like Django rest framework (DRF). But I have difficulties to figure out the highlighted areas below, If someone shows some light, I will be good to go:

  1. How to handle subdomains/domains and selecting the right tenant db
  2. How to manage and dynamically handle different database in django
  3. Can multi-tenant apps backend still be managed from Django admin interface
  4. I will be using queues and other apps scalling techniques, need tips and tricks if any
  5. Any example out there
  6. Any challenge experience when developing SAAS through Django

Answer

yuvi picture yuvi · Feb 22, 2014

Well...

  1. django-subdomains
  2. There are people who asked in SO questions about dynamic databases in django (including, ahem... me). I'm not entirely sure I understood what you mean by "dynamically handle different database" so I guess just go to the links I just mentioned and pick out the best one for your project. (also - perhaps this is more relevant?)
  3. Check out django-multitenant-schemas and this answer too.
  4. There was a video of the guys behind Disqus (one of the largest django app in the world) explaining how they handle scaling. Here another interesting article on the subject. Also, the legendary SO question Does Django Scale.
  5. (and 6.) Check out this answer

I hope that's detailed enough. I know this might be a disappointing only-links answer, but this is the reality of it - Django is a newer framework, and web development with python is still less common than php. With that in mind, understand that for all the awesomness of django (and it is awesome), with more complex needs there's more you'll have to do yourself.

In this case, you'll have to figure out how to do each part of the way seperatly and then combine it all. You can easily find a way to create a REST django app for example, but then you'll need to figure out how to combine it with another package (such as the above subdomains).

You can find a million examples out there of people doing freaky things with django. It's really powerful (when I learned about dynamic models I was blown away). But the more complex your app, the more you'll need to do yourself.

Pick it up, one step at a time, and come back to SO with specific issues you're having (or the django users google group). Good luck!