Build a multi-tenant application with Angular and .NET
A multi-tenant application serves many customers from one operating platform while keeping each customer’s users, settings, files and business records isolated. With Angular on the front end and .NET behind it, the hard part goes beyond displaying a tenant name in the interface. Tenant identity must remain trustworthy at every request, database query, background job and cache entry.
A practical design starts with explicit boundaries: resolve a tenant from controlled evidence, attach its key to owned data, and authorise access through membership rather than a client-supplied identifier. The same rules apply across shared and dedicated database models. This guide follows that path from domain modelling through deployment for teams operating in Australia.
Start with the tenant boundary
First define what a tenant represents. It might be a legal company, a franchise branch, a clinic or a customer workspace, and those choices affect whether records can be shared. Model memberships separately from user identities so one person can belong to several tenants with a different role in each. Keep tenant identifiers immutable and use a slug only for display and routing.
Resolve the tenant at the edge of the application. For example, acme.example.com.au can map to a tenant record, while a path such as /acme/... can act as a fallback when custom domains are not available. The server should derive the tenant from that mapping and compare it with the authenticated user’s membership. A header such as X-Tenant-Id may identify a requested workspace, but it must never be accepted as proof of access.
Keep the resolved tenant in request-scoped context rather than mutable global state. Background jobs, webhooks and scheduled imports need the same discipline: carry an explicit tenant key in the job payload, reload it inside the job and make it available to the data-access layer. A shared cache key must include the tenant key whenever cached content can vary between customers.
Model tenancy inside the .NET API
With Entity Framework Core, a shared database is usually the simplest starting point. Give every tenant-owned table a non-null TenantId, normally represented by an EF Core relationship to Tenant. Put the discriminator in composite keys and unique indexes so a customer cannot accidentally create duplicate invoices, email addresses or external references outside its own boundary.
- Scope every tenant-owned row with a required tenant key.
- Build unique indexes around the tenant key and business identifier.
- Apply tenant filters by default, including navigation queries.
- Record approved shared reference data separately.
Global query filters reduce accidental cross-tenant reads, but they are a safety net rather than the whole design. Explicitly include tenant predicates in repositories and authorisation queries, and test administrative endpoints that deliberately operate across tenants. Sensitive operations can use a separate service or elevation path with a recorded reason.
For customers requiring stronger physical separation, use a database per tenant or a hybrid model. Keep the API and domain contracts consistent so the storage strategy can differ by account. SQL Server row-level security can provide another barrier, yet application filtering, database permissions and automated isolation tests remain necessary because each control has a different failure mode.
Authenticate users and authorise tenant data
Use an OpenID Connect provider such as Microsoft Entra ID for workforce customers, while allowing each customer to configure its own enterprise identity provider where needed. The token proves who the person is; it does not automatically prove which customer data they may use. Map external identities to internal users and tenant memberships in the database instead of relying on an email address as a permanent key.
Treat the tenant claim as a routing hint when it comes from the identity provider. After login, resolve the user’s active membership, check its status and issue application-specific permissions for that tenant. Store role names as stable identifiers and enforce them in server-side policies. Angular route guards improve the experience, but the API must repeat every relevant check because a user can call an endpoint directly.
Authorise by querying the resource within the tenant boundary, rather than fetching a record and checking its owner afterwards. That pattern closes common insecure direct object reference bugs. Add per-tenant rate limits and quotas alongside global protection, and write security-relevant events to an audit stream with tenant, actor, action and correlation identifiers. Never place secrets, raw tokens or unnecessary personal information in those audit records.
Design Angular for tenant-aware work
Make the active tenant visible and easy to change. A route such as /t/:tenantSlug/reports gives the Angular application a clear context, while a resolver can confirm access before a protected screen loads. Display the customer or workspace name in the shell, and avoid allowing a stale tenant name to remain after navigation. Deep links, refreshes and browser history should all restore the same authorised workspace.
Treat a tenant switch as a new application context. Cancel outstanding requests, clear tenant-specific stores and cached route data, then reload the shell and destination. Do not copy state between tenants merely because the user has access to both. Angular signals or services can organise this state, but the server remains authoritative about which records the selected membership can retrieve.
Choose the rendering and build strategy with performance in mind. This AOT compilation overview explains how Svelte’s approach differs from React’s virtual DOM, giving frontend teams a useful comparison between compile-time work and runtime rendering. For Angular, lazy-load feature routes, split large dependencies and keep personalised server-rendered pages out of shared caches. These choices matter when staff in regional Australia open large reports over an ordinary broadband connection.
Connect the frontend to the backend
Generate the Angular client from the .NET OpenAPI contract, then wrap it in a tenant-aware service rather than scattering URLs through components. The API can expose /api/tenants/{tenantSlug}/..., or derive the tenant from the hostname and use a shorter resource route. Whichever shape you choose, validate the slug against the authenticated membership on every request and return a consistent 404 or 403 policy that does not reveal records from another tenant.
For browser sessions, secure, HTTP-only, SameSite cookies keep access tokens away from JavaScript and require CSRF protection for state-changing calls. If the deployment uses bearer tokens, hold short-lived access tokens in memory and design refresh and revocation deliberately. The tenant header is still only a request hint; membership validation belongs in ASP.NET Core middleware and the query layer.
Send a correlation ID with each request and display it in error details shown to support staff. Use bounded timeouts, cancellation and exponential backoff for transient failures, and retry only operations that are safe to repeat. Paginate large collections, return stable sort fields and avoid returning a tenant’s entire dataset merely to make filtering convenient in Angular.
Operate the platform across Australia
Australian buyers may include accounting practices, franchise networks and NDIS service providers, so the platform often has to fit local invoicing and purchasing workflows. Support Australian dollars, ABN details and GST handling, and make exported invoices compatible with tools such as Xero or MYOB. Keep tax rules in a dedicated billing component rather than scattering assumptions through Angular forms.
Privacy and hosting decisions need an Australian lens. The Privacy Act 1988 and Australian Privacy Principles may apply to personal information, while state health and sector rules can add obligations. Assess data residency before choosing infrastructure, and measure latency to Sydney, Melbourne, Brisbane and Perth rather than assuming users sit near an office. Use plain Australian English: “organisation”, “authorise” and “cancelled” are normal spellings, and support can be friendly without becoming flippant. Keep security warnings direct, even when an internal handover might say “no worries”.
- Offer AUD invoices with ABN, GST and Xero or MYOB compatibility.
- Place latency-sensitive services near Sydney and Melbourne, then measure Perth and Brisbane.
- Keep initial bundles modest for NBN and regional fixed-line connections.
- Schedule support around Perth time, Sydney time and daylight-saving changes.
Ship with a safe path to production
Test isolation with at least two tenants that contain predictable colliding record identifiers. An integration test should prove that a valid member can read and update only the records in their tenant, while a valid token from another tenant still fails. Add unit tests for host resolution, membership checks and cache-key generation, plus contract tests between the Angular client and ASP.NET Core API.
Release schema changes with an expand-and-contract plan: add compatible columns or tables, deploy code that can read both shapes, move data, then remove old structures in a later release. Apply migrations as a controlled deployment step rather than an uncontrolled action from every API instance. Include tenant isolation checks in CI and make rollback procedures cover both application code and data changes.
Observe the system through structured logs, traces and metrics. Include the tenant and correlation IDs in logs, but keep tenant identifiers out of metric labels when many customers would create excessive cardinality. Alert on failed authorisation rates, unusual export volumes and background jobs that repeatedly cross a tenant boundary. When an incident occurs, the audit trail should let responders reconstruct the request without exposing personal details.
Start with the tenant resolver, two isolated test tenants and one protected Angular-to-.NET workflow. Prove that the browser, API, database and job processor enforce the same boundary, then expand features around that tested foundation.