One platform, many customers: three data-isolation patterns and when to choose each
When your platform serves more than one company, the key question becomes: how do you make sure one never sees another’s data? A practical comparison of a shared database, a schema per customer, and a database per customer.
Every product sold as a subscription faces the same decision early: where does each customer’s data live? It shapes security, cost and ease of updates for years, and changing it later is expensive. There is no universally best pattern; there is one that fits your size and your customers.
Pattern one: a shared database with a customer identifier
All tables are shared and every row carries the ID of the company it belongs to. It is the cheapest and easiest to update: one migration reaches everyone. The risk is that forgetting the filter in a single query is enough to leak data. So we do not rely on developer discipline alone: the filter is enforced in one central layer, and in PostgreSQL it can be enforced inside the database itself with row-level security policies.
Pattern two: a schema per customer
One database, but each customer has its own schema with its own tables. Isolation is stronger, and backing up or restoring a single customer is easier. In exchange, every migration must run against every schema, and with hundreds of customers that becomes an operation needing tooling and monitoring.
Pattern three: a database or deployment per customer
The strongest isolation available, and it lets a customer’s data live in a country or on a server they choose, with a customised release. It also has the highest operating cost: every customer is a server or database to monitor, update and back up. It suits a small number of large customers or those with regulatory requirements.
How we choose
- Dozens or hundreds of small customers with similar needs: a shared database with centrally enforced isolation.
- Mid-sized customers who want independent backup and restore: a schema per customer.
- A few large customers, or data that must stay in a specific place: a deployment per customer.
They can be combined: a standard subscription on a shared platform, and a dedicated deployment for those who need one. That is what we offer with Novixa Aqar, for instance: managed hosting, or a licence to deploy the code on the customer’s own servers.
What no pattern may skip
- Automated tests that deliberately try to read one customer’s data from another customer’s account, and fail if they succeed.
- An audit log of who viewed what and when, especially for support and admin accounts.
- A documented way to export one customer’s data in full and delete it when the subscription ends.
In short
Isolation is an architectural decision made in week one, not a feature added before launch. Choose the pattern for the customers you expect in two years, not today, and make the tests prove isolation instead of assuming it.
id: ADR-tenant-isolation
status: <proposed | accepted>
context:
expected_customers_in_2_years: <number>
data_location_requirements: <none | country/provider per customer>
per_customer_restore_needed: <yes | no>
options:
shared_db_with_tenant_id: cheapest, one migration, needs enforced filtering
schema_per_tenant: stronger isolation, migrations run per schema
deployment_per_tenant: strongest isolation, highest operating cost
decision: <option>
enforcement:
- tenant filter applied in one central layer
- PostgreSQL row-level security policies (if shared_db)
- cross-tenant read tests that must fail
- audit log for support/admin access
- documented per-customer export and deletion