Choosing how to separate customer data
A SaaS product needs to keep each customer's data separate across queries, background jobs, exports and support tools. A tenant_id field helps identify ownership, but the application also needs controls that enforce it.
Shared tables, separate schemas and separate databases each place those controls differently. Their costs also differ when you need to restore one customer, investigate an incident or meet a specific isolation requirement.
Model one: shared tables with a tenant column
Every tenant lives in the same tables. A tenant_id column on each row says who it belongs to, and the application adds that filter to every query.
Why shared tables are cheap to run
This is the cheapest model to run by a wide margin. One database, one schema, one migration per change. Onboarding a new customer is an insert, not an infrastructure task. Reporting across all customers is a normal query. For a product with many small accounts, nothing else comes close on operational simplicity.
Where shared tables fall short
The isolation lives entirely in your code. One missing filter in one endpoint, one report built in a hurry, and a customer sees another customer's invoices. That is the failure everyone fears, and it does happen, usually in admin tools and exports rather than in the main product.
The other costs are quieter:
- Noisy neighbors. One tenant running a huge import slows everyone, because they all share the same tables, indexes and connections.
- Restores. Restoring a single customer's data after they delete something by mistake means pulling their rows out of a full backup, table by table. It is possible, but nobody enjoys doing it at two in the morning.
- Compliance requests. "Delete all our data" and "keep our data in the EU" are both harder when that data is interleaved with everyone else's.
The safety net: row-level security
If you stay with shared tables, put the database in charge of isolation, not only the application. Postgres row-level security lets you attach a policy to each table so a connection can only see rows for the tenant set on that session. A forgotten filter then returns nothing instead of returning someone else's data.
It is not free. Every request has to set the tenant context reliably, background jobs need the same care, and policies need tests like any other code. But it turns "we trust every developer to remember" into "the database enforces it", which is a much better answer to that security questionnaire.
Two PostgreSQL caveats catch teams out. First, table owners and roles with the BYPASSRLS attribute skip policies, and superusers always do. Unless you also enable FORCE ROW LEVEL SECURITY on the table, the application must connect as a non-owner role without that attribute, or the policies protect nothing. Second, with transaction-mode connection pooling a session setting can leak to, or vanish from, the next request that reuses the connection. Set the tenant context per transaction with SET LOCAL (or set_config with its local flag set) so it cannot outlive the request. Check the details against the documentation for your PostgreSQL version.
Model two: a schema per tenant
Each tenant gets its own schema inside a shared database: the same table definitions, separate namespaces. The application switches schema per request.
Why a schema per tenant separates well
Isolation is visibly stronger. A query that forgets about tenancy can only touch the current tenant's schema. Exporting or deleting one customer is a matter of dumping or dropping one schema. Restoring a single tenant from backup becomes realistic. You can even give a large customer slightly different indexes if their usage demands it.
Where a schema per tenant falls short
Migrations. A schema change is no longer one migration but one per tenant. With fifty tenants that is a loop. With two thousand it is a deployment that takes long enough to need its own monitoring, and a failure halfway leaves some tenants on the new structure and some on the old one. Your code must cope with both until the run finishes.
Database catalogs also grow with every schema, and some tooling, from ORMs to monitoring, assumes one schema and gets awkward with thousands. Noisy neighbors are still a problem, because everyone shares the same server.
This model fits a middle ground: tens to low hundreds of tenants, each with meaningful amounts of data and a real need to be separable.
Model three: a database per tenant
Every tenant has their own database, sometimes on their own server.
Why a database per tenant isolates best
This is the strongest isolation you can offer short of separate deployments. The security answer is simple and convincing. Backups and restores happen per customer. Data residency is solved by placing a customer's database in the region they require. A tenant who hammers their database affects only themselves, and you can size their server to their load or bill them for it.
Where a database per tenant falls short
Operations. Every database needs provisioning, monitoring, backups, connection management and upgrades. Migrations fan out across every database, with the same partial-failure problem as schemas, but now across machines. Cross-tenant reporting means collecting data from many places into a separate warehouse. Costs scale with the number of customers, not just with their usage, which hurts if you have many small accounts.
Database per tenant makes sense for a small number of large or regulated customers. It rarely makes sense for everyone.
Moving between models later
Here is the part teams underestimate: you will probably not stay in one model forever. The common path is to start with shared tables, grow, and then move a handful of enterprise customers into their own schema or database because a contract requires it.
That move is far easier if you prepared for it from the beginning:
- Tenant ID everywhere. Every row, every file in storage, every cache key and every queue message carries the tenant. If it does, extracting one tenant is a filtered copy. If it does not, it is archaeology.
- No cross-tenant foreign keys. If tenant data references shared reference tables, keep those small and easy to copy.
- A routing layer. Resolve "which database and schema serves this tenant" in one place. Then moving a tenant means copying their data and changing one entry in that lookup.
- Tested extraction. Move a test tenant from shared tables to their own database regularly, before a customer is waiting for it.
A similar idea applies to growth in general. In one of our projects, a multi-tenant SaaS built on a single Laravel monolith needed to prepare for ten times its traffic. Part of the answer was a database sharding strategy that spread tenants across several databases, alongside queues and caching. The scaling case study describes how the work was sequenced and what it achieved. The sharding step was only manageable because tenant boundaries were already clear in the data.
A decision guide
There is no universal answer, but a few questions narrow it down quickly.
Mostly small customers, no special compliance demands
Shared tables with a tenant column and row-level security. Spend the operational budget you save on tests that prove isolation, especially in exports and admin screens.
Tens or hundreds of customers with substantial data each
Consider a schema per tenant, or shared tables with a clear plan for moving larger customers out. Check that your migration tooling can handle running across every tenant before you commit.
A few large customers with contracts about isolation or residency
Database per tenant for them, possibly alongside a shared pool for everyone else. A hybrid is normal and nothing to apologize for.
Not sure yet
Start shared, make the tenant ID universal, put a routing layer in place, and turn on row-level security. That keeps every later option open at a modest cost today.
Where to start
If you already run a multi-tenant product, two hours are enough for a useful check. List every place tenant data is stored: tables, files, caches, search indexes, logs and analytics. For each one, write down how tenant isolation is enforced and who would notice if it failed. The gaps on that list are your real isolation model, whatever the architecture diagram says.
If you are about to build one, decide the model before the first customer signs, and write the decision down with the conditions that would make you change it. Our page on SaaS development covers how we approach tenancy, billing and integrations from the first sprint.
Two related product decisions need their own plans: enterprise SSO connects customer identities, while audit logs preserve a history of actions within each tenant.


