We develop a bigger SaaS application based on ASP.NET Core and EFCore. We separate tenants by database, means that we have one database for each tenant.
The database is migrated on any incoming request by a client by a custom middleware. This required, because the application should be immediately available after a tenant signed up on our SSO-Server.
So the pipeline looks like this:
Unfortunately this has some downsides, as I recognized later:
Long introduction, short question: Can anyone judge whether this migration workflow is a good practise? If not: Do you have a better idea how I can achieve multi tenancy?
I read about Global Query Filters in EFCore 2.0, but I'm not sure how safe this approach is regarding data isolation.
Thanks!
SQL Database supports row-level security, which can enforce that data returned from a query be scoped to a single tenant. Processing: A multi-tenant database shares compute and storage resources across all its tenants.
We can implement multi-tenancy using any of the following approaches: Database per Tenant: Each Tenant has its own database and is isolated from other tenants. Shared Database, Shared Schema: All Tenants share a database and tables. Every table has a Column with the Tenant Identifier, that shows the owner of the row.
What is a benefit of developing applications in a multi-tenant environment? Developing applications in a multi-tenant environment enables multiple users or customers to share the same underlying resources (i.e., database and hardware).
In a multi-tenant architecture, multiple instances of an application operate in a shared environment. This architecture is able to work because each tenant is integrated physically, but logically separated; meaning that a single instance of the software will run on one server and then serve multiple tenants.
I think creating a database per each tenant is not practical. If you have 2000 tenants, then you have to maintain 2000 database instances!
I recommend using 1 database for all the application and tenants. And add a TenantId
to most of tables so you can find out which tenant this specific records belong to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With