Skip to content
Kumar Chandrachooda
Series

Multi-Tenancy in .NET with EF Core

In reading order.

  • 10 parts
  • ≈ 50 min total
  • 10 published
Part 1 15 Jul 2025 4 min read

Three Ways to Isolate a Tenant in .NET and PostgreSQL

Database-per-tenant, schema-per-tenant, or packed into a shared database? Kicking off a series on building a multi-tenant platform where one EF Core codebase supports all three isolation strategies behind a single control plane.

Part 2 24 Jul 2025 5 min read

Resolving the Tenant on Every Request

Header, route, subdomain or query string: how the platform decides who is asking before it touches any data, how tenant identity becomes a connection string and a schema, and where the caching knives are hidden.

Part 3 04 Aug 2025 5 min read

Making EF Core Migrations Schema-Aware

EF Core wants one database, one model and one migrations history table. Schema-per-tenant breaks all three assumptions. Constructor-injected migrations, a per-schema history table and a replaced IMigrationsAssembly put one migration set in charge of every tenant schema.

Part 4 24 Aug 2025 5 min read

The Model-Cache Trap: Why Only One Tenant Migrates

You built schema-aware migrations, provisioned tenant A, and everything worked. Tenant B provisions without a single error — and gets no tables. EF Core's model cache is the silent culprit, and IModelCacheKeyFactory is the three-field fix.

Part 5 18 Sep 2025 5 min read

Provisioning Tenants at Runtime

A signup click becomes a real PostgreSQL database or schema in seconds. Running CREATE DATABASE from application code feels illegal until you contain it — identifier validation, quoted DDL, idempotent steps, and a status machine that admits when provisioning fails.

Part 6 26 Oct 2025 5 min read

A Control Plane Needs Its Own Domain Model

Tenants are data too. The tenant-management database is the one single-tenant database in the whole platform, and its five entities — Tenant, TenantConnection, TenantFeature, DatabaseGroup, TenantMigrationHistory — carry every decision the rest of the series depends on.

Part 7 02 Dec 2025 5 min read

Tenant Offboarding: Soft Delete, Purge and Restore

Deleting a tenant is the most dangerous button in the platform — behind it sit DROP SCHEMA CASCADE and DROP DATABASE. A two-step lifecycle with global query filters, a SaveChanges interception and an explicit purge keeps the blast radius survivable.

Part 8 09 Jan 2026 5 min read

Rolling Out Migrations Across a Tenant Fleet

Shipping a migration to one database is a deploy step. Shipping it to every schema in every group database is an orchestration problem — cross-database MigrateAsync, an HTTP migration surface, a per-tenant audit ledger, and the honest gap where the fan-out loop should be.

Part 9 12 Feb 2026 5 min read

The PostgreSQL Payoff: ltree Hierarchies and jsonb Payloads

Seven parts of migration machinery existed to deliver one table — a hierarchical crumb trail with three ltree columns, a jsonb payload, GiST and GIN indexes, and a Dapper read side that speaks PostgreSQL's native operators. This is why it was PostgreSQL all along.

Part 10 14 Mar 2026 6 min read

Multi-Tenancy Retrospective: What I'd Do Differently

Nine parts of architecture posts lie by omission unless the tenth is the ledger. What earned its keep — isolation as data, MaxTenants = 1, the schema-keyed model cache — and the honest list of shortcuts: plaintext connection strings, cache windows, reflection, and a fan-out loop that still says TODO.