2 November 2026
Build a Multi-Tenant SaaS Platform with Django: A Practical Guide for Indian Startups
You are building a SaaS product for Indian businesses. Your first customer is a small team in Pune. By next quarter, you have ten more customers across Bangalore, Delhi, and Mumbai. Each one needs the...

You are building a SaaS product for Indian businesses. Your first customer is a small team in Pune. By next quarter, you have ten more customers across Bangalore, Delhi, and Mumbai. Each one needs their own data, their own settings, and their own sense of privacy. If you share a single database without boundaries, you are asking for a hard conversation later. A multi-tenant architecture solves this. It keeps each customer’s data separate while letting you run one codebase. This guide walks you through building that system with Django, using tools and patterns that work well for Indian startups in 2026.

Key Takeaway

This tutorial teaches you to build a multi-tenant SaaS platform using Django. You will learn three isolation strategies, how to set up tenant-specific routing with a simple middleware approach, and which database pattern fits your startup’s scale. The guide includes a decision table, a checklist for common mistakes, and deployment tips tailored for Indian hosting environments like DigitalOcean or AWS India.

Understanding Multi-Tenancy in Django

Multi-tenancy means one instance of your software serves many customers (tenants). Each tenant believes they have their own private application. In Django, you have three common ways to achieve this.

The Three Isolation Strategies

  1. Shared database, shared schema: All tenants live in the same database and same tables. A tenant_id column on every row separates the data. This is the cheapest to run and the easiest to start with. It is also the riskiest if you forget a filter in a query.
  2. Shared database, separate schemas: Each tenant gets their own schema inside the same database. Django can handle this with PostgreSQL schemas and the django-tenants library. It gives better isolation than a simple column, but it requires PostgreSQL.
  3. Separate databases: Each tenant gets their own database. This offers the strongest isolation. Your infrastructure cost goes up with every tenant. It is usually overkill for a pre-series A startup.

For most Indian SaaS founders starting out, option one is the right call. You can always migrate to option two or three later.

Setting Up Your Django Project for Tenants

Start with a standard Django project. We will add a layer that automatically scopes every query to the current tenant.

Step 1: Add a Tenant Model

Create a new app called tenants. Inside tenants/models.py, add a simple model.

from django.db import models

class Tenant(models.Model):
    name = models.CharField(max_length=100)
    subdomain = models.CharField(max_length=50, unique=True)
    created_on = models.DateField(auto_now_add=True)

    def __str__(self):
        return self.name

Every tenant gets a unique subdomain. When a user visits yourstartup.puneshop.example.com, the subdomain puneshop tells Django which tenant to load.

Step 2: Write Tenant-Aware Middleware

Middleware runs on every request. Your middleware will read the subdomain from the host header and attach the tenant object to the request.

from django.utils.deprecation import MiddlewareMixin
from tenants.models import Tenant

class TenantMiddleware(MiddlewareMixin):
    def process_request(self, request):
        host = request.get_host()
        subdomain = host.split('.')[0]
        try:
            request.tenant = Tenant.objects.get(subdomain=subdomain)
        except Tenant.DoesNotExist:
            request.tenant = None

Add this middleware to your settings.py file. Make sure it runs early in the middleware stack.

Step 3: Scope All Queries to the Tenant

Now you need every model in your app to respect the tenant. The cleanest way is to use a model manager that filters by the current tenant.

class TenantManager(models.Manager):
    def get_queryset(self):
        return super().get_queryset().filter(tenant=current_tenant)

You can fetch current_tenant from a thread-local variable or from the request object using a simple utility function. For a beginner-friendly approach, use a global thread-local variable that your middleware sets before each request.

Choosing Your Database Strategy

This decision affects your hosting costs and your ability to scale. Here is a comparison table to help you decide.

Strategy Isolation Level Cost per Tenant Migration Complexity Best For
Shared DB, shared schema Low Very low Low Early stage, under 100 tenants
Shared DB, separate schemas Medium Low Medium Mid stage, 100 to 1000 tenants
Separate databases High High High Enterprise, regulatory compliance

A senior engineer I know once told me: “The best multi-tenant architecture is the one you can actually ship. Do not build a fortress for a village.” Start with shared schema. Move to schemas when you see real pain.

Common Mistakes Indian Founders Make

Avoid these errors to save yourself a weekend of debugging.

  • Forgetting to filter by tenant in admin views. The Django admin panel will show all tenants’ data unless you override get_queryset.
  • Using the tenant subdomain as a primary key. A tenant might rebrand or change their domain. Use an auto-incrementing ID internally.
  • Ignoring database connection pooling. If you use separate databases, each request might open a new connection. Use a pooler like pgbouncer for PostgreSQL.
  • Not testing with multiple tenants. Your staging environment should have at least three test tenants with overlapping data.

Deployment Considerations for India

Hosting costs in India can vary widely. Here are practical tips.

  • Use a single $10 per month VPS from DigitalOcean or AWS Lightsail for your first 50 tenants. A shared schema strategy keeps the database light.
  • Set up your CDN to cache static assets per tenant. Many Indian ISPs have variable latency. A CDN with a point of presence in Mumbai or Bangalore helps.
  • Schedule your backups by tenant. If one tenant corrupts their data, you want to restore only their records.
  • Consider data localization if you serve government or regulated industries. Keep your database server in India. AWS has a Mumbai region. DigitalOcean has a Bangalore region.

A Checklist for Your First Multi-Tenant Launch

Before you go live, run through this list.

  • Tenant middleware is installed and tested with valid and invalid subdomains.
  • Every model that holds tenant data has a foreign key to the Tenant model or uses a tenant-aware manager.
  • The Django admin panel has custom get_queryset methods for tenant scoping.
  • Your signup flow creates a new Tenant record and a new superuser for that tenant.
  • You have a way to seed demo data for new tenants without exposing other tenants’ data.
  • Your CI/CD pipeline runs tests with multiple tenant scenarios.

What to Do When Your SaaS Grows

You will eventually hit a ceiling with the shared schema approach. Here is how to plan for the upgrade.

When your database queries start slowing down because of the sheer volume of rows, consider moving to separate schemas. The django-tenants library handles this well. You keep one database server but get logical separation. Your migration path looks like this.

  1. Install django-tenants and configure it for your existing database.
  2. Create a new schema for each tenant and copy their data.
  3. Update your middleware to use the library’s schema routing.
  4. Drop the old shared tables after you validate the new setup.

This process can be done with zero downtime if you use a maintenance page for a few minutes during the data copy.

Your Next Steps as a Technical Founder

You now have a working blueprint for a multi-tenant SaaS platform with Django. Start with the simplest isolation strategy. Write the middleware. Test with two tenants on your local machine. Deploy to a cheap VPS in Bangalore. Add your first paying customer. Only then think about scaling to separate schemas.

Building for Indian startups means you understand the cost sensitivity of your customers. A multi-tenant architecture lets you offer a lower price point because your infrastructure is shared. Use that advantage. Ship your product. Fix the architecture when the revenue justifies it.

If you want to see how this fits into a broader development strategy, check out our guide on top web development trends to boost your business in 2026. For tools that can speed up your workflow, read about essential web development tools every startup should use. And to make sure your platform stays fast for users across India, take a look at 7 best practices for optimizing web applications for Indian mobile users in 2026.

Go build something that works for your customers today. The perfect architecture can wait until tomorrow.

Leave a Reply

Your email address will not be published. Required fields are marked *