Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: django-db-multitenant: multiple tenants in a single Django app server (github.com/mik3y)
1 point by mik3y on July 25, 2013 | hide | past | favorite | 1 comment


Little more background for the HN Django crowd:

This was inspired from an older HN discussion here: https://news.ycombinator.com/item?id=4270003

I wanted to take a Django app not designed for multitenancy and serve several tenants from a single Django gunicorn instance. Scaling to support more tenants beyond the server's capacity is just a matter of turning up a new appserver (from a baked AMI in my case).

It works with MySQL by issuing a new ``USE`` statement whenever the current request's resolved tenant (database) does not match the connection.

Tenant mapping is abstracted into a method that takes a request and returns the database name. In my case, that's a lookup against a Redis server using the request's hostname.

It's a bit devious (as noted in the README!) but works well for my limited application. Perhaps someone else will find it useful.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: