Tenant isolation patterns for multi-tenant SaaS

Silo, pool and bridge are choices made per resource, not once per product. A decision table, a PostgreSQL row-level security script you can run yourself, and the controls that keep noisy neighbours in check.

Every multi-tenant system makes the same promise twice. Tenant A never sees tenant B's data, and tenant A's busy afternoon never becomes tenant B's outage. The first promise is about data isolation. The second is about performance isolation. Teams often design hard for the first and discover the second in production.

Both promises are kept, or broken, one resource at a time. A product can share its web tier, give each tenant its own database, and still run every tenant's background jobs on one queue. So the useful question is "which resources are shared, and what enforces the boundary on each?", asked again for compute, storage, queues, caches and search indexes.

Silo, pool and bridge

The AWS Well-Architected SaaS Lens names three patterns [1]. In the silo model, a tenant has dedicated resources: a full stack, or perhaps a separate database. In the pool model, tenants share resources, which is "the more classic notion of multi-tenancy". The bridge model is the mixed case, where some parts of the system are siloed and others pooled, for example one microservice per tenant and another shared.

Two details in that definition matter more than the labels. First, a silo tenant still goes through shared identity, onboarding and operations; without that, the result is a managed service with separate copies of the product, not SaaS [1]. Second, the choice is made per service. AWS gives the reasons: a service's regulatory profile and its noisy-neighbour behaviour can push it towards silo, while agility, access patterns and cost push another towards pool [1].

Microsoft's Azure Architecture Center makes the same point with different words. It describes isolation as a spectrum rather than a discrete property, and lists vertically partitioned deployments (most tenants shared, some dedicated) and horizontally partitioned ones (a shared application tier with a database per tenant) between the two extremes [2].

A decision table, resource by resource

The table below is our own synthesis, built from the trade-offs in [1] and [2]. Read it per resource, not per product.

Question about this resourcePoints to siloPoints to poolBridge pattern that often fits
Does a contract or regulator require physical or account-level separation?YesNoSilo only the data store that holds the regulated data
How many tenants, and how fast are they onboarded?Few, onboarded by projectMany, self-servicePool by default; silo as a paid tier
Is load spiky or dominated by a few large tenants?Yes, and the spikes are unpredictableLoad is small per tenant and fairly evenSilo the heavy component (often the database), pool the rest
Do tenants need their own configuration, versions or maintenance windows?YesNoSilo for the tenants that need it; one codebase for all
What is the cost of one bad deployment?Must stay with one tenantShared risk is acceptableProgressive rollout across stamps or tiers
Do you need cross-tenant reporting?Harder: queries span many storesEasy: one storePool an analytics copy; keep the operational data isolated
Who enforces the boundary?Infrastructure and credentialsApplication code and the databaseBoth, depending on the resource

The last row is the one teams skip. In a silo, a request that reaches the wrong database fails because the credentials do not work there. In a pool, the boundary is a tenant identifier and the code that checks it [2]. That code needs a second line of defence.

Pooled data in PostgreSQL: row-level security

AWS Prescriptive Guidance is direct about pooled PostgreSQL: row-level security (RLS) "is required to maintain tenant data isolation in a pooled model", and it should be enabled on every table that holds tenant data [3]. It also recommends that the application set a tenant context at runtime, instead of creating a database user per tenant [3].

The script below follows that approach. With two invoices for tenant A and one for tenant B loaded (the seed rows are not shown), it returns the results given in the comments when run on PostgreSQL 16.15.

-- Schema owner runs this. The application connects as app_rw, which owns nothing.
CREATE TABLE tenant (
  tenant_id uuid PRIMARY KEY,
  name      text NOT NULL
);

CREATE TABLE invoice (
  invoice_id   bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  tenant_id    uuid   NOT NULL REFERENCES tenant (tenant_id),
  amount_paise bigint NOT NULL CHECK (amount_paise >= 0)
);
CREATE INDEX invoice_tenant_idx ON invoice (tenant_id);

ALTER TABLE invoice ENABLE ROW LEVEL SECURITY;
ALTER TABLE invoice FORCE ROW LEVEL SECURITY;   -- applies the policy to the owner too

CREATE POLICY invoice_tenant_isolation ON invoice
  USING      (tenant_id = NULLIF(current_setting('app.current_tenant', true), '')::uuid)
  WITH CHECK (tenant_id = NULLIF(current_setting('app.current_tenant', true), '')::uuid);

CREATE ROLE app_rw NOLOGIN NOSUPERUSER NOBYPASSRLS;  -- grant LOGIN separately
GRANT SELECT, INSERT, UPDATE, DELETE ON invoice TO app_rw;
GRANT SELECT ON tenant TO app_rw;

Per request, the application opens a transaction, sets the tenant, and runs its queries:

BEGIN;
SELECT set_config('app.current_tenant', '11111111-1111-1111-1111-111111111111', true);
SELECT count(*) FROM invoice;                        -- 2: only tenant A's rows
INSERT INTO invoice (tenant_id, amount_paise)
VALUES ('22222222-2222-2222-2222-222222222222', 1);  -- ERROR: new row violates row-level security policy for table "invoice"
ROLLBACK;
SELECT count(*) FROM invoice;                        -- 0: no tenant context, no rows

Why each line is there

  • USING and WITH CHECK. USING decides which existing rows are visible to SELECT and available to UPDATE or DELETE. WITH CHECK is evaluated against the proposed new row, and a failing row raises an error [4]. Without it, a policy's USING expression is reused as the check [4], but writing both makes the intent obvious to a reviewer.
  • set_config(..., true). The third argument makes the value last only until the end of the current transaction [6]. This matters with connection pools. PgBouncer in transaction pooling mode assigns a server connection to a client only for the duration of a transaction, and lists session-level SET/RESET as unsupported in that mode [7]. Neither document addresses set_config(..., true) behind a pooler directly. Our inference from the two is that a transaction-scoped value should not leak into the next client's transaction on the same server connection. Treat that as a hypothesis to test with your pooler and its version before relying on it, not as documented behaviour.
  • current_setting(..., true) and NULLIF. With the second argument true, a missing setting returns NULL instead of raising an error [6]. On PostgreSQL 16.15, once a transaction-local value has ended, the setting reads back as an empty string for the rest of the session, and ''::uuid raises an error. NULLIF turns both cases into NULL, so the comparison is never true and no rows match. The table fails closed either way, but a predictable empty result is easier to handle than a cast error.
  • FORCE ROW LEVEL SECURITY and a role that owns nothing. Superusers and roles with BYPASSRLS always bypass row security, and table owners do too unless the table is forced [5]. Run as a superuser, the same SELECT count(*) returns all three rows with no tenant set, even with FORCE in place. The application must therefore connect as a plain role that owns nothing; migrations run as the owner.
  • The index on tenant_id. Every query now carries a tenant predicate, so the column belongs in an index, usually as the leading column of composite indexes.

Limits worth knowing

PostgreSQL states that policies are not applied when the system performs referential integrity checks or validates constraints. A failed insert into a unique column can reveal that a value exists elsewhere, and the documentation recommends surrogate keys over keys with external meaning [4]. In a pooled schema, make unique constraints include tenant_id where the business allows it, so that two tenants can each have invoice number 1001 without learning about each other.

RLS also says nothing about where the tenant identifier comes from. Take it from the authenticated session on the server, never from a request parameter, and set it in one place in the data-access layer. Policies are permissive by default and combine with OR; a restrictive policy combines with AND and is the tool for adding conditions that must always hold [4].

Noisy neighbours

Performance isolation needs its own design. Microsoft's description is plain: when one tenant uses a disproportionate share of resources, other tenants' performance degrades, and sharing a resource carries noisy-neighbour risk "that you can't completely avoid" [8]. AWS says the same of pooled PostgreSQL, and adds that PostgreSQL by default is not aware which tenant is consuming resources, so tenant-level monitoring needs instrumentation in the application [9].

The controls we would put in place, mapped to the sources:

  1. Measure per tenant. Tag logs, traces and query metrics with the tenant identifier, so that a spike can be attributed [8][9]. Without this, every other control is guesswork.
  2. Rate-limit and throttle per tenant at the edge. Quotas through throttling or rate limiting stop one tenant from consuming the shared capacity [8]. Return 429 Too Many Requests, which may carry a Retry-After header saying how long to wait [12], so well-behaved clients slow down; the companion article on enterprise API reliability covers the client side.
  3. Bound expensive queries. Microsoft suggests a maximum record count or query time limit for tenant operations [8]. In PostgreSQL, statement_timeout aborts any statement that runs longer than the limit; the documentation advises against setting it in postgresql.conf because it affects all sessions [10]. A per-role default with ALTER ROLE ... SET applies at login only, not after SET ROLE [11], so set it for the role the application logs in as.
  4. Move heavy work off the request path. Reports and exports can run asynchronously at quieter times [8], or against a read replica [9].
  5. Move a heavy tenant out of the pool. When one tenant's load is structurally different, move it to a dedicated database or stamp. This is the bridge model used as a release valve.

The same thinking applies to anything generated on behalf of a user, including AI-generated SQL. The guards in making natural-language SQL safer (read-only roles, timeouts, row limits) are also noisy-neighbour controls.

Designing for tenants to move

Point 5 only works if moving a tenant was planned for. Azure separates logical tenants from deployments and keeps a mapping that routes each tenant's requests to the deployment holding its data [2]. Building that mapping from the first release costs little: one table and one lookup in the request path. It lets you place a large tenant on its own database later without a rewrite. Azure also notes the cost on the code side: a codebase that serves both shared and dedicated deployments has to be designed for both [2].

Testing the boundary

Azure's guidance ends with a reminder to test that one tenant's data is not leaked to another [2]. A short checklist for reviewing a pooled design:

  • An automated test for each endpoint that creates data as tenant A and tries to read, update and delete it as tenant B.
  • A test that runs the application role with no tenant context and asserts that tenant tables return nothing.
  • A catalogue check in CI that lists any table with a tenant_id column but RLS disabled, not forced, or without a policy:
SELECT c.relname, c.relrowsecurity, c.relforcerowsecurity,
       count(p.polname) AS policies
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
JOIN pg_attribute a ON a.attrelid = c.oid AND a.attname = 'tenant_id' AND NOT a.attisdropped
LEFT JOIN pg_policy p ON p.polrelid = c.oid
WHERE c.relkind IN ('r', 'p') AND n.nspname = 'public'
GROUP BY c.relname, c.relrowsecurity, c.relforcerowsecurity
HAVING NOT c.relrowsecurity OR NOT c.relforcerowsecurity OR count(p.polname) = 0;

On the schema above, this query reports only the tenant table itself. That is correct: the registry of tenants needs its own decision, either a policy or an explicit exemption recorded in the check.

Isolation is an architecture decision that is expensive to reverse, and one we work through early with teams building SaaS through our custom software and SaaS development and enterprise infrastructure architecture services.

Prepared with AI-assisted research and drafting.

Sources

[1] Amazon Web Services, "Silo, Pool, and Bridge Models", AWS Well-Architected Framework: SaaS Lens, AWS documentation. https://docs.aws.amazon.com/wellarchitected/latest/saas-lens/silo-pool-and-bridge-models.html

[2] Microsoft, "Tenancy models for a multitenant solution", Azure Architecture Center, Microsoft Learn, 2025. https://learn.microsoft.com/en-us/azure/architecture/guide/multitenant/considerations/tenancy-models

[3] Amazon Web Services, "Row-level security recommendations", Implementing managed PostgreSQL for multi-tenant SaaS applications on AWS, AWS Prescriptive Guidance. https://docs.aws.amazon.com/prescriptive-guidance/latest/saas-multitenant-managed-postgresql/rls.html

[4] The PostgreSQL Global Development Group, "CREATE POLICY", PostgreSQL Documentation (current). https://www.postgresql.org/docs/current/sql-createpolicy.html

[5] The PostgreSQL Global Development Group, "Row Security Policies" (section 5.9), PostgreSQL Documentation (current). https://www.postgresql.org/docs/current/ddl-rowsecurity.html

[6] The PostgreSQL Global Development Group, "System Administration Functions" (configuration settings functions), PostgreSQL Documentation (current). https://www.postgresql.org/docs/current/functions-admin.html

[7] PgBouncer project, "Features", PgBouncer documentation. https://www.pgbouncer.org/features.html

[8] Microsoft, "Noisy Neighbor antipattern", Azure Architecture Center, Microsoft Learn, 2025. https://learn.microsoft.com/en-us/azure/architecture/antipatterns/noisy-neighbor/noisy-neighbor

[9] Amazon Web Services, "PostgreSQL pool model", Implementing managed PostgreSQL for multi-tenant SaaS applications on AWS, AWS Prescriptive Guidance. https://docs.aws.amazon.com/prescriptive-guidance/latest/saas-multitenant-managed-postgresql/pool.html

[10] The PostgreSQL Global Development Group, "Client Connection Defaults" (statement_timeout), PostgreSQL Documentation (current). https://www.postgresql.org/docs/current/runtime-config-client.html

[11] The PostgreSQL Global Development Group, "ALTER ROLE", PostgreSQL Documentation (current). https://www.postgresql.org/docs/current/sql-alterrole.html

[12] M. Nottingham and R. Fielding, "Additional HTTP Status Codes", RFC 6585, IETF, 2012. https://www.rfc-editor.org/rfc/rfc6585