An app that demonstrates the implementation of: One Database Per User/Customer.
The logic is handled in a single application instance.
In other words, each user should have their own database. Most SaaS products run in this architecture of data handling.
- There is a centralized
routing-tablewhich pointsuser1todatabase1. - While user creation, the routing-table instance is created on the default database.
- The database is created dynamically on runtime for the user. The user instance is then created on the user specific database.
- While login, the routing table is searched with the
usernameor the unique identifier. - Depending on the database where the user's data is stored. The auth credentials are checked and then authenticated.
- After authentication, the database to be used is set on the
local-thread. - We have customised the
database-routerto get the data from thelocal-threadand query accordingly. - We have also used
cookiesto persist the user's auth and related data.
- Python3.9.6
- Virtualenv
- Create a virtual environment in the project root using
virtualenv -p python3 venv. - Activate the environment & install the packages inside
requirements.txtfile. - Use pre-commit to maintain code integrity. Run:
pre-commit install. - Run the app using
python manage.py migrate && python manage.py runserver.
- https://books.agiliq.com/projects/django-multi-tenant/en/latest/isolated-database.html
- https://oroinc.com/b2b-ecommerce/blog/single-tenant-vs-multi-tenant/
Your thoughts, suggestions, feedback, comments and PR's are welcome 😊
