Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6361959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:50:42+00:00 2026-05-24T23:50:42+00:00

I’ve been brooding over the right/optimal way to create a multitenancy application based on

  • 0

I’ve been brooding over the right/optimal way to create a multitenancy application based
on Django.

Some explanation:

  • Application can be used by several tenants (tenant1, tenant2, …,).

  • All tenant-individual data has to be secured against access of other tenants (and their users).

  • Optionally tenants can create additional custom-fields for application-objects.

  • Of course, underlying hardware limits number of tenants on one “system”.

1) Separating each tenant by e.g. sub-domain and using tenant-specific databases in the underlying layer

2) Using some tenant-ID in the model to separate the tenant-data in the database

I am thinking about deployment-processes, performance of the system-parts (web-server(s), database-server(s), working-node(s),…)

What would be the best setup ? Where are the pro’s and con’s?

What do you think?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:50:42+00:00Added an answer on May 24, 2026 at 11:50 pm

    We built a multitenancy platform using the following architecture. I hope you can find some useful hints.

    • Each tenant gets sub-domain (t1.example.com)
    • Using url rewriting the requests for the Django application are rewritten to something like example.com/t1
    • All url definitions are prefixed with something like (r'^(?P<tenant_id>[\w\-]+)
    • A middleware processes and consumes the tenant_id and adds it to the request (e.g. request.tenant = ‘t1’)
    • Now you have the current tenant available in each view without specifying the tenant_id argument every view
    • In some cases you don’t have the request available. I solved this issue by binding the tenant_id to the current thread (similar to the current language using threading.local )
    • Create decorators (e.g a tenant aware login_required), middlewares or factories to protect views and select the right models
    • Regarding to the databases I used two different scenarios:
      • Setup multiple databases and configure a routing according to current tenant. I used this first but switched to one database after about one year. The reasons were the following:
        • We didn’t need a high secure solution to separate the data
        • The different tenants used almost all the same models
        • We had to manage a lot of databases (and didn’t built an easy update/migration process)
      • Use one database with some simple mapping tables for i.e. users and different models. To add additional and tenant specific model fields we use model inheritance.

    Regarding the environment we use the following setup:

    • Nginx
    • uWSGI
    • PostgreSQL
    • Memcached

    From my point of view this setup has the following pro’s and con’s:

    Pro:

    • One application instance knowing the current tenant
    • Most parts of the project don’t have to bother with tenant specific issues
    • Easy solution for sharing entities between all tenants (e.g. messages)

    Contra:

    • One quite large database
    • Some very similar tables due to the model inheritance
    • Not secured on the database layer

    Of course the best architecture strongly depends on your requirements as number of tenants, the delta of your models, security requirements and so on.

    Update: As we reviewed our architecture, I suggest to not rewrite the URL as indicated in point 2-3. I think a better solutions is to put the tenant_id as a Request Header and extract (point 4) the tenant_id out of the request with something like request.META.get('TENANT_ID', None). This way you get neutral URLs and it’s much easier to use Django built-in functions (e.g. {% url ...%} or reverse()) or external apps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.