I have a django application and i've needed to create multiple instances. So currently i create a virtualenv for each instance with its own django project. However this is not scaling well. What i really need is multiple instances of the application inside a single django project.
Is there any sort of examples or advice for something like this? I was thinking of using multiple databases, but then each db would get all of the models for all applications in the project.
I think you would like to see Multi Tenant Applications in Django.
If you follow this book it contain what you are looking for. Building Multi Tenant Applications with Django
Taken from the above shared docs.(Summary)
The various approached to multi tenancy
Shared database with shared schema
Shared database with isolated schema
Isolated database with a shared app server
Completely isolated tenants using Docker
Related
I am using Django Rest Framework for backend development, where I have set up 2 environments. I have split settings files as required and both the environments have different DBs which are working fine, I am using Zappa(AWS lambda) for deploys, I was wondering is there an elegant way of migrating data(not models but data inside models say a few config changes) than preparing PostgreSQL DB rollouts, Could not find much on the internet, so asking here.
Please let me know if there are any questions.
I am using Django as the back end and Nuxt as the front end, with Postgres as the database. I would like to have different tables/databases for each domain.
The Django code and the Nuxt code will be the same for all sites.
The way the app is set up, it requires different domains to have different databases or at least different tables.
At the moment, I am thinking I need to create a separate installation of Django/Nuxt for each domain. But I am wondering if there is a better way?
Setting up different Code bases for every domain is not a good idea at all. I had an app that was set up that way and soon we were struggling to maintain the same code and DB structure for all the different domains. After a few domains, it will become tricky.
I would suggest developing a multi-tenant SAAS based app, where you can have multiple tenants running the same Django/Nuxt code but having different schemas in the Postgres, So your database for different domains will be completely separate from each other. I would suggest using django tenant schemas for this. Even if it takes you some time to set it up, I would suggest doing it. It will save a great deal of time for you in the future.
I build 2 flask Apps App1 and App2(Two different services). Both Apps are referring to the same DB. Am using MongoDB as database and MongoEngine to create connections and to support ORM Queries.
I have created a user table in App1 and I defined the structure of the table in models.py file. Now I have to use the same user table in the App2. How would I use the existing table itself without rewriting the same code in APP2?
I can do it in one way that I can write a Mongo wrapper which will connect and serve the data. But I don't want to write RAW queries. Can someone help me how to do this? Thanks!
You can put all your database-related code into a separate Python package which both your applications can then import.
OR
You could also consider building a separate application around your database code that exposes information through an API. Your other applications could then make requests to this API.
So, I am new to this "monolith vs microservices" architecture debate and I have pretty much understood most of it. From my limited understanding I get it that in microservice architecture each feature(lets say) is a separate app. Now I need some clarification with respect to django for implementing microservices. Heres my question
Should I make every microservice aka the app a different django project altogether OR should I make every app aka the microservice inside one django project and keep them isolated (as in loosely coupled) ?
Microservice architecture simply states that your each service should be independent of each other.
Its also not necessary to create one micro-service in java and one in python since they are not related.
So yes, ideally your each micro-service is a separate django project.
The best way to break this, first list down all the possible modules in your site or app.
Then go through :
https://microservices.io/patterns/decomposition/decompose-by-business-capability.html
https://microservices.io/patterns/decomposition/decompose-by-subdomain.html
These are two recommended pattern of how you should divide modules / domain into micro-services.
well, you can use database routers in django ... that does the trick ... one wSGI file per app communicating with your NGINX server
The main purpose of micro service is to serve the specific business, for example you are running a cloud kitchen then Django project can have many sub projects under one master project or you can run each project as separate service, it up to you.
Service
backoffice
finance
rider
kitchen
now we will set the url for each service like
Endpoints
backoffice.mycompany.com
finance.mycompany.com
rider.mycompany.com
kitchen.mycompany.com
Once our app is up the service load will not effect other service.
The microservice should be completely independent so it should not belong to one Django project. You should be able to deploy each service independently with its own database, so even you split the project into separate apps they still share one physical database and you can not deploy them separately. Therefore, you could potentially create separate Django project for each 'microservice' but this does not make much sense. You put lot of overhead for creating a microservice and also using Django framework is not a best choice for MSA , have a look at Flask.
For our project we host both the website and the actual webapp on one AppEngine instance. I separated them both nicely in different projects, but they all share the same settings file. It's becoming more and more clear to me that these should actually be independent django instances as they use different settings for middleware, template loaders, etc.
So I tried running two django instances on the same server (different handlers), but because django uses global variables for caching all over the place, which the AppEngine runtime caches between requests, I couldn't get this to work reliably. Did anyone successfully do this before?
Since you can run multiple app versions simultaneously, I would put this independent django instances in different app versions.