Django and multi-tenancy: The isolated database approach

N Aditya (~n38)


In the Software-As-A-Service(SAAS) world, the term multi-tenancy is a huge buzz word. There are different approaches that software companies around the world have devised to solve this problem. Typically when a new web app is built, it tends to be deployed for one specific customer (single-tenant). But when the number of customers grow, spinning up an entire server cluster for each customer results in a huge wastage of infrastructure resources. In this talk, the motive is to explain how a pip-installable package has been built, which when plugged into any single-tenant app, existing or new, would instantly make it multi-tenant by configuring just a few parameters. Though the concept is generic and can be extended to any web framework, the package is currently built for Django. Also, the spotlight would be on the isolated database approach where every tenant/customer gets its own separate database.

Talk Outline

  • Introduction (4-5 mins)
    • What is multi-tenancy and the commonly adopted approaches
    • The isolated DB approach and the two major problems it entails.
  • Solving dynamic routing of DB queries (7-8 mins)
    • Explain what the end objective is with an example.
    • Explain the solution architecture diagram.
    • Code walkthrough and demo.
  • Solving the dynamic tenant configuration problem when an Add/Update/Delete tenant occurs. (8 mins)
    • Explain the end objective and methods which aren't suitable to solving this ( like graceful restart etc.,)
    • Explain the background event listener approach along with constraints/problems it entails.
    • Code walkthrough and demo.
  • Other topics of interest (4 mins)
    • DB migrations
    • Modified CACHES to support multi-tenancy.
    • Unit testing methods in the new paradigm.


  • Prior experience with building a Django based web app.
  • Basic knowledge of the micro-services architecture.
  • Basic knowledge of how multi-threading and multi-processing works in Python

Video URL:

Speaker Info:

Aditya is a passionate tech evangelist who loves experimenting with bleeding edge technology and tries to apply them to complex engineering problems in simple and elegant ways. He has deep rooted skills in various technologies ranging from full stack web development to DevOps and IoT. He has a very keen eye for design with regards to UI/UX, product lifecycle management and engineering. His decision making is greatly driven by strong logical reasoning and philosophy. On the professional front, he has been in the industry for about 4 years and during this tenure, has worked with Fortune 500 companies as well as early stage startups. Some of his work highlights are:

  • Built a comprehensive device for enhancing mobility and manoeuvrability of the physically challenged and disabled people via facial gesture recognition on a smartphone. -> At Intel IoT roadshow 2016
  • Designed a multi-project SAAS architecture (re-usable Django app) which pivots data based on a specific Django model by automatically adding filters, computed based on the relationship type with the pivot model, in already written ORM code. On the client (angular app), changes were made to routing, data storage and component/service lifecycle. -> At Maximl Labs, IITM research park.

Currently he works as a Software Engineer - II (R&D) at Innovaccer Inc.,

Section: Web development
Type: Talks
Target Audience: Intermediate
Last Updated: