Skip to content

Technology · 11 min read

Multi-Tenant SaaS: 3 Database Models Compared

Abidhusain ChidiFounder and CEO

Multi-tenant SaaS database models drawn as three chalk cylinders: shared rows, a schema each and a database each

Key takeaways

  • Most multi-tenant SaaS products should start on a shared schema, with a tenant_id on every tenant-owned row.
  • PostgreSQL row-level security catches a forgotten tenant filter, but superusers, owners of unforced tables, views they own and constraint checks get around it.
  • Set the tenant with SET LOCAL inside each transaction, because a plain SET outlives the request on a pooled connection.
  • Database per tenant isolates best, and multiplies databases, migrations, backups and connection pools with every customer.
  • Give an enterprise customer its own database through a tenant directory, on the same schema and code as everyone else.

Multi-tenant SaaS keeps customer data in one of three database models: a shared schema, one schema per tenant, or a separate database for each tenant. Usually the right start is the shared schema, backed by PostgreSQL row-level security, with only the customers whose contracts demand it moved onto a database of their own. Below, the three are compared on isolation, migration effort, noisy neighbours and what each new tenant adds to the hosting bill.

Multi-tenant SaaS database models drawn as three chalk cylinders: shared rows, a schema each and a database each

This guide is for product teams deciding how a SaaS product should hold customer data, and for anyone whose app was built for one customer and now needs a second. It covers the architecture side of multi-tenant SaaS development. On our builds every tenant-owned table carries its account, so a new customer is an inserted row, not a deploy, and the products we run ourselves use the same pattern. What each choice costs is in our SaaS development cost guide.

Single-tenant vs multi-tenant SaaS, in plain terms

A single-tenant product gives each customer a separate copy: its own application, its own database and often its own server. A multi-tenant product runs one copy for everyone. The tenant, usually a company account, then becomes a boundary inside the data and inside every request.

The line is less tidy than it sounds. AWS’s SaaS Lens on silo, pool and bridge models (read 25 November 2026) still counts a tenant on dedicated resources as SaaS, provided identity, onboarding and operations stay shared. Separate versions with separate onboarding are what it calls a managed service. So the real test is one codebase and one release for every customer. Where one customer’s rows sit is a placement decision you can make later.

Multi-tenancy is the wrong goal for some products. Skip it when the software must be installed on each customer’s own servers. Skip it, too, when three or four large clients each want their own features and release dates: that is a managed service, so price it as one. An internal system for one organisation does not need it either, because keeping its legal entities apart is a different problem from separating customers.

The three multi-tenant SaaS database models side by side

All three keep customers apart. They differ in where the boundary lives, what a schema change involves, and what grows every time you sign a customer.

QuestionShared schemaSchema per tenantDatabase per tenant
Where the boundary livesA tenant_id on each tenant-owned rowA schema name, picked per requestA connection, picked from a tenant directory
IsolationAs good as the query filter, plus a database policy if you add oneNamespace only, unless each tenant gets its own roleStrongest: a missed filter cannot reach another database
A schema changeRuns onceRuns once per schemaRuns once per database
Noisy neighboursShare tables, indexes and the serverShare the serverShare the server unless a tenant gets its own
Restoring one tenantRestore a copy, then move that tenant’s rows back by handRestore a copy, then dump and reload one schemaDump and reload one database
What a new tenant adds to the billRows and storageA schema, its tables and indexes, one more migration targetA database to provision, pool, back up and monitor
FitsMost productsA modest number of tenants that need separate namespacesA few large or regulated tenants

Read the last two rows together and the pattern is clear: the shared schema adds data with each customer, while the other two add things somebody has to operate.

What each new tenant adds in a multi-tenant SaaS: rows for a shared schema, a schema and a migration run for schema per tenant, a database, pool, backup and migration run for database per tenant
The shared schema grows data; the other two grow things somebody has to operate

Shared schema: one set of tables

Every tenant-owned table gets a tenant_id column, and the tenant leads the indexes and the unique constraints. An invoice number has to be unique within one customer, not across all of them. One migration changes every customer at once, and a new tenant costs nothing but rows.

The catch is that the boundary holds only where the code applies it. One query without its tenant filter can return another customer’s data, which is why the next section adds a check inside the database. Everyone also shares the same server, so one tenant’s heavy export slows the rest. A statement timeout on the application’s role, never in postgresql.conf where the manual says it would affect all sessions, plus rate limits per tenant, keeps that in bounds.

Schema per tenant: one namespace each

Each tenant gets its own schema with identical tables, and the application points each request at the right one, usually through search_path. Tables stay small, and removing a customer is a single DROP SCHEMA … CASCADE.

Two things make it weaker than it looks. First, a schema is a namespace, not a lock. PostgreSQL’s schema documentation says a role cannot reach objects in another role’s schema until that owner grants USAGE. Yet if the application connects with one role that can use every schema, the only thing between tenants is a setting. Second, every migration now runs once per schema, and a run that fails halfway leaves tenants on different versions.

Database per tenant: one database each

Each tenant gets its own database, and a tenant directory maps the account to its connection details. This is the strongest of the three. A forgotten filter cannot reach another customer’s rows. One tenant can be dumped, restored, moved to another region or deleted without touching the rest. The cost is a fleet: every new tenant adds a database to provision, migrate, back up and monitor, and connections run out quickly.

The connection arithmetic

PostgreSQL’s max_connections setting is typically 100 by default. PgBouncer, the pooler in the PostgreSQL stack we use, keeps a separate pool for each user and database pair, and its default_pool_size (read 25 November 2026) is 20 server connections. So five tenant databases on default settings can claim every connection the server allows, and ten would want 200.

Pooled connections at 20 per tenant database against the PostgreSQL default limit of 100: five databases fill it and ten need 200
PgBouncer default pool of 20 per database against max_connections of 100, drawn to scale

You can shrink the pools, but then each tenant gets fewer connections at its busiest hour. Also, databases on one server still share its CPU, memory and disks. Database per tenant only removes noisy neighbours when the busy tenants move to servers of their own.

Row-level security for multi-tenant SaaS on PostgreSQL

Row-level security is a PostgreSQL feature that applies a policy to normal queries against a table and drops the rows the policy rejects. It is part of the PostgreSQL stack we typically use, and on our builds we choose the isolation method, row-level security or schema per tenant, at design time instead of after a leak.

For a shared schema the pattern has four parts. The application connects as a role that owns no tables. Each tenant-owned table has row security enabled and forced. One policy compares the row’s tenant_id with a setting. Finally, the application sets that value at the start of each transaction with SET LOCAL.

Code
-- migrations run as the table owner; requests run as app_rw
CREATE ROLE app_rw LOGIN;
GRANT SELECT, INSERT, UPDATE, DELETE ON invoices TO app_rw;

ALTER TABLE invoices ENABLE ROW LEVEL SECURITY;
ALTER TABLE invoices FORCE ROW LEVEL SECURITY;

CREATE POLICY invoices_by_tenant ON invoices
  USING (tenant_id = nullif(current_setting('app.tenant_id', true), '')::bigint);

-- each request, inside one transaction
BEGIN;
SET LOCAL app.tenant_id = '42';
SELECT id, total FROM invoices WHERE status = 'open';
COMMIT;

The true passed to current_setting makes a missing setting return null instead of an error. On a pooled connection that has carried a tenant before, the setting can read back empty instead, and nullif turns that into null too. Since a null comparison never passes a policy, a request that forgot its tenant sees no rows at all.

What row-level security protects

The row security chapter of the PostgreSQL manual (read 25 November 2026) sets out the guarantees. In a multi-tenant SaaS they come down to four:

  • Forgotten filters. A query without WHERE tenant_id = … still returns only the current tenant’s rows.
  • Misplaced writes. A policy with only a USING clause applies the same test to new rows, so a write that would file a row under another tenant fails.
  • Missing policies. Turn row security on and forget to write the policy, and the table returns nothing. PostgreSQL denies by default.
  • Ad hoc queries. The policy filters a support script connected as the application role in the same way.

What row-level security does not protect

The same manual is just as clear about the exceptions. Each of these can expose one tenant’s data to another, or leave a gap the policy was never meant to fill.

Inside the database

  • Roles that skip it. Superusers and roles with BYPASSRLS always bypass the policies. So does a table’s owner, unless the table is forced. Run migrations as the owner and serve requests as a separate role.
  • Views. By default a view reads its tables with the view owner’s privileges and policies, per the CREATE VIEW reference. A reporting view owned by a superuser, or by the owner of an unforced table, can hand every tenant’s rows to the application. Create such views with security_invoker = true.
  • Constraints. Unique, primary key and foreign key checks always bypass row security, and the manual warns of “covert channel” leaks through them. A unique email across the whole table tells one tenant that an address exists at another. Put tenant_id in those constraints.
  • Session settings on pooled connections. A plain SET lasts until the session ends, and behind a pooler the session outlives the request. PgBouncer’s feature map marks SET and RESET as never compatible with transaction pooling, where a client holds a server connection only for one transaction. That is exactly how long SET LOCAL lasts. Outside a transaction block it only warns and does nothing, so wrap every request in one.

Outside the database

  • Everything PostgreSQL never sees. Cache keys, search indexes, uploaded files, logs and exports need the tenant in them as well.
  • Load and recovery. A policy is a filter, not a quota. It does not stop a noisy neighbour, and it does not restore one tenant on its own.
  • Backups, in a good way. pg_dump turns row security off and stops with an error if its role cannot bypass it, so a backup run as the application role fails loudly instead of quietly missing rows.

When an enterprise customer forces a dedicated database

Sooner or later a large prospect’s security review asks where its data sits and who shares the server. The request for a dedicated database usually rests on a contract clause that requires separation, data that has to remain in one region, encryption keys the customer holds, a restore promise for their data alone, or worry about noisy neighbours. AWS’s page on silo isolation lists compliance and the absence of noisy neighbours among the reasons to dedicate resources.

Most products can say yes without becoming single-tenant. Keep one codebase and one schema, keep tenant_id in every table even inside the dedicated database, and record in the tenant directory which database holds each tenant. Moving a customer out then means copying its rows and changing one directory entry, while the same migrations run against every database. As with SSO on our SaaS service, we scope a dedicated database as an addition to the architecture already in place and quote it in writing before building it.

Questions to settle before you say yes

  • Does “dedicated” mean its own database, its own server, or its own cloud account?
  • Which region must the data stay in, backups and logs included?
  • Who holds the encryption keys, and what happens if the customer revokes them?
  • What recovery point and restore time are promised for this customer’s data?
  • Who pays the extra running cost, and is it written into their tier?

Not every request deserves a yes. If the account is small and the ask is a preference, a dedicated database can cost more to run than the contract brings in.

Moving a single-tenant app to multi-tenant SaaS: the order of work

A product built around one customer is one of the three problems our SaaS page names as the usual starting point. Account IDs are hard-coded into queries, and each new customer needs a code change before they can use the product. The work starts with a short audit of what the data model needs and which code can be adapted. Tenant isolation for products moving to many customers is also part of our app scaling audit. Then the order matters:

  1. List what assumes one customer: tables, unique constraints, jobs, cache keys, file paths, reports, integrations and settings held in environment variables.
  2. Add the tenant model: a tenants table, memberships linking users to tenants, and the existing customer as tenant one.
  3. Add tenant_id in small steps. Add it as nullable, backfill it with tenant one, then make it required and add it to foreign keys and unique constraints.
  4. Resolve the tenant once per request from the memberships of the user who is logged in, never from a URL or a form field, and pass it through one data-access layer.
  5. Carry it outside requests: jobs, scheduled tasks, cache keys, storage paths, exports and outgoing webhooks.
  6. Switch on row-level security table by table, with the application on a role that owns nothing.
  7. Test across the boundary. Create two tenants with look-alike data and try every read, edit and export from one against the other.
  8. Make sign-up create a tenant, and only then bring the second customer on.

What the conversion usually misses

The quiet failures sit in places nobody thinks of as data. Invoice numbers that used to be global now need a sequence per tenant. Integrations that held one set of credentials now need a set per tenant. Support also needs a deliberate, logged way to look across tenants, because the admin panel is the one place where crossing the boundary is the job.

Run the conversion on the shared schema even if one customer will later need its own database. Placement can change at any time, whereas a missing tenant column has to be retrofitted through every query.

How to choose a multi-tenant SaaS database model

Start with the shared schema when your customers use the same features on the same release, which describes most products. Add row-level security as the backstop, and put the tenant in caches, files and jobs from the first sprint.

Use a database per tenant for the named accounts whose contracts require it, placed through the tenant directory and priced into their tier. Choose schema per tenant only with a specific reason, such as tenants that each need their own extensions to the schema, and plan a role per tenant before the second one arrives.

Whichever you choose, write the decision down with the reason. Once real customers depend on it, the tenancy model is the hardest part of a SaaS build to reverse.

TagsArchitectureDataSecurityPostgreSQLSAASSaaS Development

Written by

Abidhusain Chidi

Founder and CEO

Founder of QalbIT Infotech and the engineer who still scopes most of its projects. Writes about what custom software really costs, how build-versus-buy decisions play out two years in, and the delivery habits that keep a product shipping, drawn from CRM, ERP, SaaS and MVP work Abid has been building since 2014 and the products QalbIT runs itself today.

FAQ


Frequently asked questions

A single-tenant product runs a separate copy of the application and database for each customer. A multi-tenant product runs one copy for everyone and keeps each customer's data apart inside it, with a tenant column, a schema per tenant or a database per tenant.
For most products, the shared schema: one set of tables with a tenant_id on every tenant-owned row, backed by PostgreSQL row-level security. Individual customers can move to a database of their own later, if a contract requires it.
It is a strong backstop, not the whole answer. It filters rows a query forgets to scope, but superusers, roles with BYPASSRLS and owners of unforced tables skip it, constraint checks bypass it, and caches, files and search indexes sit outside it.
When a contract requires separation, the data must stay in one region, the customer holds the encryption keys, or a restore promise covers their data alone. Keep the same schema and code, and record where the tenant lives in a tenant directory.
Yes, mostly in operations. Every tenant adds a database to provision, migrate, back up and monitor, plus its own connection pool. At PgBouncer's default pool of 20 and PostgreSQL's usual limit of 100 connections, five tenant databases can use up the whole limit.
Usually, yes. Audit what assumes one customer, add a tenants table, add tenant_id in small steps with a backfill, resolve the tenant once per request, then switch on row-level security and test with two tenants. See our SaaS product development service.
Only if each tenant connects with its own role. With one application role that can use every schema, the boundary is just a search_path setting, and every migration has to run once per schema.

Newsletter

Join 1,000+ smart readers

One email a month on building software that ships. Unsubscribe anytime.

Next step


Want the same clarity for your product?

A short call. A written range. No obligation.