[SOLVED] Multi Tenancy separated by database: saas, schema and maintenance
- 0
- Databases
- Self Hosted

You asked for resources if I'm not wrong to learn? 😅

I know where to find AppWrite docs, and it is, indeed, well documented. But I'm asking if there are any best practices for creating a SaaS application in AppWrite since information like this isn't something you'd likely find in the docs but more rather on a blog or forum. But I don't think you can help me with my problem. I will close this thread now.

Oh, yes, I can help you

And other people too

@TheIlluminatiMember Tell me firstly what data or what kind of data you will have and I will try to find the best way you could structure it

Without that I can't determine what is the most optimal solution

@TheIlluminatiMember Correct me if I'm wrong.
You want to have a main
database that stores the various tenants
. Now you also want to have a different database for each tenant
, that all have the same structure, correct?


Just to be sure, this is what you want to do right?

If this is what you want to do, I suggest isolating all this behaviour inside of one Database.

What you could do is, create a database called master
.
Inside master
, have a collection called main
which stores all your tenants in documents.
You can then create collections for all your tenants inside of the master
database, by following a naming convention like tenant-[name/id]
. Whatever data you want to store for each tenant, can be done easily in the form of documents, and since it's all inside one single DB, you won't have to worry about referencing a new Database when updating.

What I'm looking for is a structure like this.

Yes, that's correct. You don't need to have more than 2 databases for that

Yes I do, because in this example I only have 1 tenant named Test

The Light blue database is linked to a tenant in the main database

If I have 2 tenants there should be 2 light blue databases

You should associate documents with the tennant document with a relationship or manually with an ID In cloud, instead of having independent databases

I may consider going for that approach but I would much rather make use of the databases since it would be very easy to query data from it depending on which tenant is using the application.

So when you want to get all associated, you basically apply a filter for that

Yes, but as said, it's not the most optimal

Yes, you can use separate databases for each of your tenants. As others have mentioned, it doesn't create a separate mariadb database but is a way to segregate data into different mariadb tables.
I can't place this logic in the function because that would mean when I create a tenant now and update the function later the existing tenants would not be updated.
I think functions are the way to go, but, as you said, existing tenants would need to be updated. maybe manually...maybe your function can update the existing ones too. it all depends on you.

Thank's for clearing things up for me @Steven! I'll create functions to not only create but also update tenants. I will mark this as solved now.

[SOLVED] Multi Tenancy separated by database: saas, schema and maintenance

But collections don't separate data into different tables?

Each collection is a separate mariadb table
Recommended threads
- Deploy sites confusion (1.7.4) / Node
Hi, I have a project with two version of the same website. One if in french, the other in english. They share the same databases and storage but I've deployed ...
- 1.7.2 Node-appwrite createDocuments from...
Am I correct in my testing that functions with document creation event, wont trigger on calling createDocuments from within a function.
- I am Trying to create my own SMS gateway...
i am using appwrite 1.2.1, where can i edit or add new customSms.php which folder should i check ? then how can i manage to edit appwrite orginal code
