I have been struggling with the way I should set up my multi-tenant environment. In a previous project I had set it al up as a monolith where there was a tenant entity to bind al the correct data to each other. This way is quite easy to set up but the data of all tenants is in one big database.
My idea now is to set it all up in a different way. I will be using Postgres because of the possibility to also have 'schema'. My idea is to have overall data in the public schema and tenant specific data in the tenants own schema.
There are some struggles that I face where I just can not get my head around. In the picture below, you see a quick sketch of the two scenarios. The bottom one has everything in the public schema where the above one has for example domain and user in the public schema.
My idea with this is that when a customer goes to a tenants specific URL the application does not have to crawl through all possible schemas. Same counts for user. When a user wants to login to the application we also do not want to crawl through all schema's. But how do I set this up in a proper way?
Also when the user manages his domains (add/edit/delete), he is actually managing them on the public schema. Or should I avoid using public at all? I thought of putting them here because otherwise when a user enters a new domain I have to check them also on other tenants schema.
Also can I just simple set the schema name of the tenant in the domain or should this be a connectionstring?
I also read here and there about multi-tenancy but I'm unsure how the application can get the data of a tenant with the use of a different schema (public) to fetch the correct data from the tenants schema. Should I use Inversion of Control to get a specific implementation depending on calling for Domain (public schema) or customer (tenant specific)?
https://nebulab.it/blog/how-to-switch-solidus-ecommerce-to-multi-tenant/
https://michael-mckenna.com/multi-tenant-asp-dot-net-core-application-tenant-resolution