Skip to main content
🏗 Backend architecture

Multi-tenant SaaS on .NET 10: Three Levels of Tenant Isolation and When to Move Between Them

When namespace isolation is enough, when you need schema-per-tenant, and when each customer needs a dedicated cluster. SLAtech's experience: 200+ tenants on the same backend, with no unplanned isolation moves.

By Emil Slavin · June 11, 2026 · 15 min read

⚡
TL;DR

Multi-tenant ≠ tenant_id in the WHERE clause. Isolation, regulation, latency, observability: everything changes at each level.

3
isolation levels
15 min
reading time
.NET 10
production stack
200+
tenants in the cluster

Context

A multi-tenant SaaS is a system that serves many customers ("tenants") from the same codebase and infrastructure. The alternative, a separate deployment for each customer, may look simpler but becomes operationally hard to maintain once you reach scale.

Technically there are three classic levels of isolation. Each one is a trade-off between density (how cheaply a tenant can be hosted) and safety (how well tenants are isolated from one another when something goes wrong).

Below, we describe each level, our implementation at SLAtech on .NET 10, and the triggers that move a given tenant up to the next level.

Level 1: isolation by namespace (shared everything)

All tenants share one process, one DB, and one schema. Isolation works through a TenantId column in every table and a filter in an EF Core query interceptor:

// In DbContext OnModelCreating:
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
    if (typeof(ITenantScoped).IsAssignableFrom(entityType.ClrType))
    {
        var param = Expression.Parameter(entityType.ClrType, "e");
        var prop = Expression.Property(param, nameof(ITenantScoped.TenantId));
        var tenantIdValue = Expression.Constant(_tenantContext.CurrentTenantId);
        var filter = Expression.Lambda(
            Expression.Equal(prop, tenantIdValue), param);
        modelBuilder.Entity(entityType.ClrType).HasQueryFilter(filter);
    }
}

When it works: small to mid-sized B2B SaaS with up to a few hundred tenants and similar loads. Cost per tenant: tens of agorot a month.

Where it breaks:

  • One tenant starts running heavy reports, and everyone gets degradation.
  • Someone forgot the filter in the query interceptor in a single call that runs once a year, and data leaks between tenants. This will happen if there is no code review discipline + autotests on isolation.
  • One tenant requires regional data residency under regulation (European GDPR, ISO 27018 for the cloud).

Level 2: schema-per-tenant (shared infrastructure, isolated data)

One process, one DB server, but a separate schema for each tenant. EF Core switches schemas dynamically based on the request context. In PostgreSQL this is search_path; in SQL Server, a schema prefix on every command.

// Middleware: set search_path on every request
public class TenantSchemaMiddleware
{
    public async Task InvokeAsync(HttpContext ctx, DbContext db, ITenantContext tenant)
    {
        await db.Database.ExecuteSqlRawAsync(
            $"SET LOCAL search_path TO {SanitizeSchema(tenant.SchemaName)};");
        await _next(ctx);
    }
}

When to move up from Level 1:

  • A tenant asks for regulatory separation of data (European GDPR versus Israeli requirements).
  • One tenant's data reaches 100GB+: the indexes no longer fit in the shared buffer pool, and everyone suffers.
  • You need a per-tenant pgvector index with different parameters (we see this under RAG load).

The cost: migrations are now n times more complex. Every EF migration runs on every schema. Our pipeline is parallelized, but the window for errors grows.

Level 3: cluster-per-tenant (dedicated infrastructure)

A separate DB, a separate cache, sometimes a separate application process. One repo; different runtime instances. Managed through Terraform + a GitHub Actions matrix.

When to move up from Level 2:

  • An enterprise tenant requires a 99.95% SLA with an independent blast radius. One fault on shared infra = a lost SLA for everyone; a separate cluster solves the problem both politically and technically.
  • Strict regulation (healthcare with patient data, banking-grade compliance): the customer wants the ability to audit separate infrastructure.
  • On-prem: the tenant hosts it on their own premises. That is effectively cluster-per-tenant already, just in someone else's cloud.

The cost: cost per tenant rises 50-100 times compared with Level 1. It only pays off at enterprise pricing.

Triggers for moving between levels

Not knowing in advance which level each tenant will end up on is fine. What matters is building in the ability to move. We use the following signals:

TriggerMove
Tenant DB size > 50 GBFrom L1 to L2
A regulator requires data residencyFrom L1 to L2 or L3
SLA 99.9%+ or enterprise pricingFrom L2 to L3
On-prem deploymentFrom L1 or L2 to L3
Tenant > 30% of total loadFrom L1 to L2 (to prevent a noisy neighbor)

What you must do at Level 1 so you do not suffer later

  1. Every table with user data goes through the ITenantScoped interface. No exceptions. An audit script in CI checks that new tables inherit the interface.
  2. All query interceptors are centralized. No raw SQL that bypasses EF without explicit TenantId injection and without code review.
  3. Isolation autotests. Create two tenants, fill them with data, then try to read one tenant's data through the other tenant's API: the test must fail. We have 47 of these, and they run on every PR.
  4. A migration path from L1 to L2 ready from the first month. A script "extract tenant data - new schema - switch tenant config - drop source" is written and tested on a synthetic tenant. When a real customer arrives with the requirement, there is no reason to panic.
  5. Logging with TenantId on every line. Otherwise, in an incident, you cannot tell the difference between "broken for everyone" and "broken for one tenant who is shouting loudly".

Where .NET 10 helps

  • Improved AsyncLocal performance: we store TenantContext through a DI scope + AsyncLocal, and it is no longer on the hot path.
  • EF Core 10 query filters got smarter with the plan cache: a per-tenant filter used to invalidate the plan; now it does not.
  • Native AOT, where possible: for microservices without EF, we are moving to AOT, which cuts the cost per tenant on L1 by roughly another 30%.

Moving an existing single-tenant product to multi-tenant

Most products do not start out multi-tenant. They start as a separate installation for each customer and end up here when the tenth installation is harder to maintain than the product itself. Bringing tenancy into a system that is already running is a different problem from designing it in from the start: there is live data, there are customers on different versions, and there is code that assumes it is alone.

  1. First, bring all customers onto one version. Separate installations drift apart over time: different versions, urgent fixes, code written for one customer. Multi-tenant requires a single codebase, so customer-specific code has to become configuration or feature flags before anything else moves.
  2. Start with schema-per-tenant (Level 2). Each customer's existing DB moves into its own schema with almost no code changes, so the first step is consolidating the infrastructure, not rewriting the product. Moving tenants into a shared schema can come later, one at a time.
  3. Add TenantId to every table, and to the keys as well. Constraints that were unique within one installation, such as an invoice number, a username, or an SKU, become unique per tenant. Forget this, and you get collisions after consolidation.
  4. Identify the tenant at the entry point. Every request has to know which tenant it belongs to before it touches any data: by subdomain, by a claim in the token, or by the API key. Users who lived in separate installations may need a single identity, or SSO per tenant.
  5. Find everything that lives outside the DB. Background jobs, cache, file storage, search indexes, queues, and scheduled reports were written for a single customer. Each of them needs the tenant in its key or path, and that is usually where cross-tenant leaks hide after the move.
  6. Move one customer at a time, with a way back. Start with a small customer, compare their data before and after, and keep the old installation available until the new one has been through a full business cycle.

The isolation tests from Level 1 are the safety net here. Create two tenants, fill them with data, and try to read one from the other: the test must fail. Run them before the first real customer moves over.

Frequently asked questions

What are the main architectural challenges in moving from single-tenant to multi-tenant?

Bringing all customers onto one version, adding TenantId to the data and to the unique keys, identifying the tenant on every request, and scoping everything outside the DB by tenant: background jobs, cache, files, search indexes, and queues.

Should a single-tenant product move straight to a shared DB?

Usually not. Schema-per-tenant lets you move each customer's existing DB with almost no code changes. Tenants can be consolidated into a shared schema later, one at a time.

How do you move customers over safely?

One customer at a time, starting with a small one, comparing data before and after, and keeping the old installation available until the new one has been through a full business cycle. The isolation tests run before the first move.

Takeaways

  1. Most B2B SaaS products should start at Level 1. Do not overcomplicate it.
  2. ITenantScoped discipline + isolation autotests: a contract that cannot be broken. Without it, Level 1 is a time bomb.
  3. Put a migration path from L1 to L2 in place from the first month. When an enterprise tenant arrives, you will have 2 weeks, not 3 months.
  4. Level 3 only at enterprise pricing. Never give away a "separate cluster" as a marketing bonus.
Further reading

What to read next

📚

AI Glossary

Normalized terms in 4 languages

🔒

AI Security

Prompt injection and audit trail in multi-tenant

📊

AI Monitoring

OpenTelemetry for AI applications

🎯

Domain-specific AI

Vertical AI vs a generic chatbot