Multi-tenancy is the foundation of almost every SaaS product: one application serving many customer organizations, each with its own users and data. Getting it right early saves painful rewrites later. This guide covers how to build a multi-tenant SaaS with ASP.NET Core, from choosing a tenancy model to billing and scaling.

1. Choose a tenancy model

ModelIsolationCost to runOperational complexity
Shared database, tenant ID columnLogicalLowestLowest
Shared database, schema per tenantMediumLowMedium
Database per tenantStrongHigherHigher (migrations, connections)
HybridPer tierBalancedMedium

For most new products we recommend a shared database with a tenant ID, designed so a large or regulated customer can later be moved to a dedicated database. Microsoft's multitenant architecture guidance covers the trade-offs in depth.

2. Resolve the tenant on every request

Common strategies are a subdomain (acme.yourapp.com), a claim in the user's token, or a header for API clients. Whatever you choose:

  • Resolve it in middleware early in the pipeline and store it in a scoped ITenantContext service.
  • Derive it from a trusted source (the authenticated token), not from a value the client can freely change.
  • Reject requests where the user does not belong to the resolved tenant.

3. Enforce isolation in the data layer

With EF Core, apply a global query filter to every tenant-owned entity so queries are automatically scoped:

protected override void OnModelCreating(ModelBuilder b)
{
    b.Entity<Invoice>().HasQueryFilter(i => i.TenantId == _tenant.Id);
}

public override Task<int> SaveChangesAsync(CancellationToken ct = default)
{
    foreach (var e in ChangeTracker.Entries<ITenantOwned>()
                 .Where(e => e.State == EntityState.Added))
        e.Entity.TenantId = _tenant.Id;
    return base.SaveChangesAsync(ct);
}

Add a database index that starts with TenantId on large tables, and consider row-level security in SQL Server or PostgreSQL as a second line of defense. Most importantly, write automated tests that attempt cross-tenant access and must fail.

4. Authentication and roles

  • Use an identity provider (Microsoft Entra ID, Auth0, Keycloak or ASP.NET Core Identity) and put the tenant and roles in the token.
  • Support organizations, invitations and per-tenant roles (owner, admin, member).
  • Offer SSO (SAML / OpenID Connect) for enterprise tenants — it is often a requirement in larger deals.

5. Billing and plans

Use Stripe (or a similar provider) for subscriptions, trials, plan changes and invoices. Store each tenant's plan and status locally, update it from webhooks, and enforce plan limits — users, projects, API calls — in your application code.

6. Background jobs and messaging

Emails, imports, reports and AI tasks belong in background workers (hosted services, Hangfire, Azure Functions or queues). Always pass the tenant ID with each job and re-establish the tenant context in the worker.

7. Configuration and customization per tenant

Keep per-tenant settings (branding, feature flags, limits) in data, not code. Feature flags let you roll out features to selected tenants and offer plan-based features cleanly.

8. Observability and support

  • Include the tenant ID in every log entry and trace.
  • Track usage and performance per tenant to spot noisy neighbours.
  • Build a secure internal admin tool for support staff, with audit logging of every action taken on behalf of a tenant.

9. Scaling

ASP.NET Core applications scale horizontally well when they are stateless: keep sessions and caches in Redis, files in blob storage and long work in queues. When a single database becomes the bottleneck, move the largest tenants to dedicated databases first — the hybrid model.

Key takeaways: start with a shared database and tenant ID, resolve the tenant from a trusted source, enforce isolation with EF Core filters and tests, put tenant context in logs and jobs, and plan a path to dedicated databases for large customers.

Building a SaaS product? Our SaaS development services cover architecture, billing and deployment, and our SaaS MVP guide helps you scope the first release.