Sébastien Rigaux

Tech watch

← All links

Multi-tenancy

Architecture allowing multiple tenants to share an application while isolating their data.

A cube-shaped logo made of gray blocks, with an orange block in the center.

Finbuckle.MultiTenant provides ASP.NET Core with tenant resolution, per-tenant configuration, and data-isolation building blocks. A basic setup combines a host-based strategy, a configuration-backed store, and the UseMultiTenant() middleware.

The middleware must run before components that depend on the tenant, such as authentication and authorization. The library also includes integrations for per-tenant options, authentication, and Entity Framework Core data isolation.

Banner reading “Multi-Tenant .NET, Part 4: Moving Day,” with moving boxes, a guild emblem, and an illustrated portrait.

This installment explains how to move a tenant from a shared database to a dedicated one without taking the application offline or disrupting other tenants. The catalog drives the switch, while the same EF Core model and query filter serve both isolation modes.

The migration uses an initial copy, a temporary read-only window, a delta copy, and verification before cutover. The runbook waits for the cache to expire before reopening writes, preventing instances that still hold the old connection from writing to the shared database after the switch.

BarretFound via C# Digest

A hand handles colorful network cables in front of rack-mounted equipment.

With one database per tenant, EF Core no longer needs a global query filter, a TenantId column, or a tenant-specific model cache key: the tenant is selected through a connection string resolved from a catalog database.

This isolation simplifies the model but shifts complexity to operations: each migration must be applied to every database. The article also explains how IDesignTimeDbContextFactory lets dotnet ef create the context without an active request or tenant.

BarretFound via C# Digest

Graphic titled “Multi-Tenant .NET, Part 2 — Shared Database with Schema Separation,” showing a “House for Rent” sign, a circular emblem with two swords, and an illustrated portrait.

Part 2/4 shows how to isolate each tenant’s data in its own SQL Server schema, without a global query filter or a required TenantId column. EF Core can use a simple primary key again, while the database structure itself enforces the isolation boundary.

The key change is model caching: OnModelCreating runs only once per model. The schema must be included in the cache key through IModelCacheKeyFactory, or EF Core may reuse the first tenant’s schema. The article also covers per-schema provisioning and migrations, plus strict validation of schema names interpolated into SQL.

BarretFound via C# Digest

Banner over a photograph of apartment buildings, titled “Multi-Tenant .NET, Part 1 — Shared Database with Partitions,” with a crossed-swords emblem and an illustrated portrait.

This first installment presents a shared-schema .NET multi-tenant design: EF Core filters reads by tenant, while SQL Server physically partitions rows to speed up data access. The key distinction is that partitioning is not a security boundary; isolation relies on the EF Core global query filter.

The article also explains resolving the tenant per request, assigning its ID to new rows, and adding partitions to migrations with raw SQL. The primary key must include GuildId, a constraint SQL Server imposes when partitioning a unique index.

BarretFound via C# Digest