Skip to content

What Is Multi-Tenant Architecture? 3 Ways to Isolate Tenant Data in SaaS

What multi-tenant architecture is, and how a shared database, schema per tenant and database per tenant compare on isolation, cost, RLS, noisy neighbors and migrations.

Published:

Multi-tenant architecture is a software design in which one application and one running system serve many customer organizations at the same time, while each customer's data stays separated from everyone else's. Each customer organization is a tenant, and every record in the system knows which tenant it belongs to. There are three basic ways to isolate tenant data: a shared database with a tenant_id column, a separate schema per tenant, and a separate database per tenant.

This guide is for technical founders, CTOs and engineering teams designing the data layer of a SaaS product. It explains how each model works, what each one gains and gives up compared with the others, how PostgreSQL row-level security (RLS) strengthens tenant isolation, and how to decide which model fits your product. How a complete platform comes together, with subscriptions, payments and an admin panel, is covered separately on our SaaS platform development page.

What is multi-tenant architecture, and how does it differ from single-tenant?

In a single-tenant setup, every customer gets a separate copy of the application: its own server, its own database and often its own version. In a multi-tenant setup there is one codebase, and a new release reaches every customer at once. Onboarding a customer is a sign-up, not an installation project. Because infrastructure is shared across many customers, the running cost per customer is usually lower, and the team maintains one system instead of dozens of drifting copies.

The price is that isolation stops being a property of the infrastructure and becomes a responsibility of the software. On separate servers, two customers' data cannot physically mix. On a shared system, code, queries and database rules have to keep it apart. A single forgotten filter in one query can let one customer see another customer's records. So the real design question is not "should we share?" but "what do we share, how much, and where do we enforce the boundary?"

The AWS SaaS architecture guidance names this spectrum with three terms: silo, where a tenant gets dedicated resources, pool, where tenants share resources, and bridge, which mixes the two (AWS Well-Architected SaaS Lens). It makes one point worth repeating: even in a silo model, identity, onboarding and operations are shared across all tenants. Running a separately managed copy for each customer is a managed service, not SaaS. We covered the general principles of a modular, growth-ready system in our post on scalable software architecture; this guide focuses on the data layer only.

What are the three ways to isolate tenant data?

1. Shared database with a tenant_id column. All tenants use the same database and the same tables. Every tenant-owned table has a tenant_id column, and every query filters on it. Adding a tenant is as cheap as inserting a row, a schema change is applied to every tenant in one go, and cross-tenant reporting is straightforward. The weakness is that isolation depends entirely on filtering correctly. That is why, in this model, the boundary should never rely on a single layer: checks in the API layer are backed by a second rule in the database, such as row-level security. Load from one large tenant also lands directly on the tables every other tenant uses.

2. Schema per tenant. There is one database server, but each tenant's tables live in their own namespace, such as a PostgreSQL schema. When a request arrives, the application switches to the right schema. Separation is more visible than with shared tables, and backing up, exporting or deleting a single tenant's data becomes simpler. In exchange, every schema change has to run in every tenant schema. As the tenant count grows, migration time, the number of objects in the database catalog and the job of tracking which schema is on which version all turn into operational work. Tenants still share one server, so resource contention does not disappear.

3. Database per tenant. Each tenant has its own database, on a shared server or on a dedicated one. This is isolation at its strongest: keeping one tenant's data in a specific region, giving it its own backup schedule or deleting all of its data at the end of a contract becomes easy. The cost is operations and automation. Every new tenant means provisioning a database, managing connections, monitoring and a backup plan. Migrations must run against every database, and cross-tenant reporting needs the data to be collected somewhere else first.

How do the three models compare side by side?

The table compares the three models on the same criteria. The ratings are relative; the real picture depends on your tenant count, data volume and how mature your automation is.

CriterionShared database + tenant_idSchema per tenantDatabase per tenant
Isolation strengthLogical; depends on correct filtering and database rulesSchema level; server is sharedStrongest; separate at database level
Cost per tenantLowestMediumHighest
Onboarding a tenantInsert a recordCreate a schema and run migrationsProvision a database and configure connections
Schema changes (migrations)Once, for all tenantsOnce per schemaOnce per database
Noisy neighbor riskHigh; tables and resources are sharedMedium; server is sharedLow; resources can be separated
Per-tenant backup, restore, deletionHard; done by filtering rowsEasierEasiest
Cross-tenant reportingEasyMediumHard; data must be aggregated
Data residency requestsAll tenants in one placeLimited to server levelDifferent region per tenant possible

In practice the models are not mutually exclusive. A common pattern keeps most tenants in a shared database and moves large customers whose contracts or data volumes require it into their own databases. This hybrid, which AWS calls the bridge model, can be added later if the application resolves the tenant context in one place from day one. If code everywhere assumes a single database connection, the same move becomes an expensive rewrite.

How does row-level security (RLS) strengthen tenant isolation?

In the shared database model, the most common cause of a data leak is a query that forgets the tenant filter. PostgreSQL row-level security (RLS) lets you handle that risk inside the database as well. Once RLS is enabled on a table, its policies are applied to every query automatically, so rows that do not match the current tenant cannot be read or modified. If RLS is enabled but no policy exists, the default is to deny everything (PostgreSQL documentation: Row Security Policies).

A typical setup writes the tenant id into a session setting at the start of each request, scoped to the transaction, and the policy reads that setting. A few details decide whether RLS actually protects you:

  • Table owners and superusers: Superusers and roles with the BYPASSRLS attribute always bypass row security, and table owners bypass it by default too. The application should connect with a separate role that does not own the tables, or the table should have FORCE ROW LEVEL SECURITY enabled.
  • Connection pooling: A tenant setting assigned at session level can leak to the next request that picks up the same pooled connection. Set it so that it only lives for the duration of the transaction.
  • Views: By default, a view accesses its underlying tables with the view owner's permissions and policies. Views that read tenant data should use the security_invoker option.
  • What RLS does not cover: Whole-table commands such as TRUNCATE, and integrity checks such as unique constraints and foreign keys, are not subject to row security. Design unique constraints to include the tenant id.

RLS is not a security strategy on its own; it is a second lock. At Detartech our standard approach enforces the tenant identifier at both the API layer and the database layer: the API resolves every request against the signed-in user's tenant and rejects requests aimed at another tenant's records, and the database layer restricts queries by tenant id as well. With both layers in place, a single bug in application code is much less likely to turn into a data leak.

How do you deal with the noisy neighbor problem?

The built-in risk of shared resources is that one tenant's heavy usage slows down the rest. Microsoft's architecture guidance calls this the noisy neighbor problem and notes that it cannot be avoided completely, only reduced (Azure Architecture Center: Noisy Neighbor antipattern). A large tenant's bulk import, a heavy report or an unthrottled integration can raise response times for every customer. It does not take a single giant tenant, either: many small tenants peaking at the same hour can have the same effect.

The mitigations come in layers. Requests are rate limited per tenant, so no single tenant can consume the whole system. Long-running work such as report generation and bulk operations moves to background queues that do not block users, with a concurrency limit per tenant. Query time and the number of returned rows get upper bounds. Monitoring shows total usage and per-tenant usage separately; if logs and metrics do not carry the tenant id, you cannot tell which tenant is causing the load. The same usage metering is also the foundation of usage-based pricing. When growth turns into a lasting bottleneck, the work shifts to database and query tuning, caching and queueing layers, which we cover under backend scaling.

How do you manage per-tenant configuration and migrations?

Per-tenant configuration. Each tenant may have its own logo, language and time zone, enabled or disabled modules and plan limits. These differences belong in the database as tenant settings, not in the code. When a customer asks for something special, the question to ask is whether it can become a setting available to every tenant or whether it would be a code branch for one customer. Tenant-specific branches look cheap in the short term, but they grow the test and maintenance burden of every release and erode the single-codebase advantage that made multi-tenancy attractive. Feature flags that roll new features out to selected tenants first can be managed from the same settings layer.

Migrations. In a multi-tenant system a schema change affects every tenant at once. The safe approach splits each change into steps that let old and new code run side by side for a while: add the new column or table first, release code that supports both shapes, move the data, and remove the old structure only when no code uses it anymore. In the schema-per-tenant and database-per-tenant models these steps run separately for each tenant. Track which tenant is on which schema version, make a half-finished migration safe to run again, and try each change on a small group of tenants before rolling it out to all of them. Without this automation, version management in a database-per-tenant system quickly becomes impossible to run by hand.

Which model should you choose? A decision checklist

Pick the model for the customer profile you expect over the next few years, not only for the one you have today. Work through these questions in order:

  • How many tenants do you expect? Hundreds or thousands of small tenants point toward the shared model; a handful of large enterprise customers point toward separate databases.
  • Do contracts or regulations require a tenant's data to stay in a specific country or in a separate database? If so, you need database per tenant at least for those tenants.
  • How uneven is usage across tenants? If a few tenants will generate most of the load, plan a structure that can move them out.
  • How often will you need to restore a single tenant from backup, or delete all of a tenant's data when a contract ends?
  • What is your team's automation capacity? Schema-per-tenant and database-per-tenant models cannot be operated without automated migrations and provisioning.
  • Is cross-tenant reporting or analytics a core part of the product?
  • If the product is not yet validated in the market, how much complexity is worth carrying today?

For most new SaaS products, a sensible starting point is the shared database with a tenant_id column, provided isolation is enforced in both the API and the database and the code resolves the tenant context in one place. Moving a large customer into its own database later then becomes a data migration and a configuration change rather than a rewrite. If the idea itself is not validated yet, starting with a narrowly scoped MVP development project before building the full platform may be the better order.

Common multi-tenant architecture mistakes

  • Trusting a tenant id sent by the client: The tenant must be resolved from the server-side, authenticated session, not from a value in the request body or the URL. Otherwise anyone who edits that value may reach another tenant's data.
  • Relying on a single layer: Trusting only the filters in application code turns one forgotten query into a data leak. We go deeper into server-side authorization checks in our vibe code security checklist.
  • Forgetting background jobs: Queued jobs, scheduled tasks and webhook handlers run without a user session. Each job has to carry the tenant id in its own payload and run under the same rules.
  • Leaving the tenant out of cache and file keys: Cache keys, file storage paths and search indexes need the tenant id as well. Otherwise data can mix through another path even when the database is separated correctly.
  • Opening tenant-specific code branches: Turning every customer request into a condition in the code splits one codebase into as many variants as you have tenants within a few years.
  • Never testing isolation: Automated tests that try to read one tenant's records as a user of another tenant belong in the suite that runs on every release.

If you are planning a SaaS product whose multi-tenant data layer, subscription billing (iyzico, PayTR or Stripe), role management and admin panel need to be designed together, you can describe it through our quick quote form. On platforms we build for clients, the code repository, database and cloud accounts are preferably opened in the client's name from the start, and the full source code and all access are handed over.

Frequently Asked Questions

What does multi-tenant mean? Multi-tenant describes an architecture in which one software application serves many customer organizations at the same time, while each customer's data is kept separate. Each customer organization is a tenant; records carry a tenant identifier and each tenant sees only its own data.

What is the difference between multi-tenant and single-tenant? In a single-tenant setup each customer gets a separate copy of the application and usually separate infrastructure. In a multi-tenant setup one codebase and shared infrastructure serve all customers. Multi-tenancy lowers the cost per customer and the effort of shipping releases, but it makes isolation the job of the software.

How do you achieve tenant isolation? Resolve the tenant from the authenticated server-side session and enforce it in at least two layers: the API authorizes every request against the tenant, and the database restricts queries by tenant id, for example with PostgreSQL row-level security. Caches, file storage and background jobs carry the same tenant id, and automated tests verify the isolation.

Is a separate database per customer more secure? It gives stronger isolation, but it costs more and needs serious automation for migrations, backups and monitoring. For most products, two-layer isolation in a shared database is enough, and large customers whose regulations, contracts or data volumes demand it can be moved to their own databases.

Is PostgreSQL row-level security enough for multi-tenancy? RLS is a strong second line of defense, but it is not enough on its own. Superusers and roles with BYPASSRLS skip policies, and table owners skip them by default. With connection pooling, the tenant setting must be scoped to the transaction. Use it together with authorization in the API layer and isolation tests.

What is the noisy neighbor problem? It is when one tenant's heavy usage degrades performance for other tenants on shared resources. Per-tenant rate limits, background queues for long-running work, query limits and per-tenant monitoring reduce the effect, and very large tenants can be moved to dedicated resources.

Can you move from a shared database to database per tenant later? Yes, but how hard it is depends on how the code was written. If the tenant context is resolved in one layer and data access can pick the right connection from it, moving a large tenant to its own database is a data migration and a configuration change. If code everywhere assumes one database, the move requires a substantial rewrite.

Have a project in mind?

Let's bring the technologies from this article to life in your project.

Request a Free Discovery Call