Note · 18 November 2026 · 7 min
Schema per tenant, and the bill that comes with it
Isolation you can prove is worth a lot. It is not free, and the invoice arrives every time you write a migration.
PostgreSQL · multi-tenancy · migrations
Deltern gives every customer their own PostgreSQL schema. A tenant is not a row with a tenant_id column — it is a namespace, and a query that forgets to scope itself fails loudly instead of quietly returning someone else’s invoices.
That property is the whole argument. In a shared-schema system, isolation is a WHERE clause that a tired person can forget in one of 761 endpoints. With a schema per tenant, the search_path is either right or the table does not exist. The database enforces the boundary because the boundary is structural.
I still think it was the right call for Deltern. I would not make it again for a different product, and the reason is worth writing down before the memory of the pain fades.
What it costs
The first bill is migrations. Sixty-eight of them, in plain SQL, and every one has to run once per tenant inside that tenant’s schema. The migrator tracks a version row per tenant in a public table, takes a lock, and runs the pending files in order. A new tenant is provisioned by replaying history from zero, which is fast now and will not stay fast.
The second bill is tooling. Prisma’s multi-schema support exists, but it wants the schema list at build time — and tenants are created at runtime. The moment a new customer signs up, a build-time list is wrong. That pushed the tenant side to raw SQL and a small query layer, which means the ORM covers the platform tables and nothing else.
The third bill is the seam between the two halves. There are 99 platform models in Prisma and around 84 tenant tables in SQL. Anything that joins across them does not exist as a single query; it is two queries and a merge in application code. That seam is where the two-headed data model came from, and it is the defect I would fix first if I started again.
The fourth bill is analytics. "How many orders across all tenants last month" is a loop, not a GROUP BY. Every cross-tenant question needs a read model, a materialised view per tenant unioned in a job, or an export pipeline.
BEGIN;
-- serialise concurrent deploys for this tenant
SELECT pg_advisory_xact_lock(hashtext($1));
SELECT version FROM public.tenant_schema_versions WHERE tenant = $1 FOR UPDATE;
-- run pending files from that version forward, each in this transaction
SET LOCAL search_path TO tenant_${id}, public;
-- ... 068_add_delivery_proof.sql ...
UPDATE public.tenant_schema_versions SET version = 68 WHERE tenant = $1;
COMMIT;Why I would choose differently next time
Istova is a managed platform with many small workspaces, not a handful of large customers. The shape of the tenancy is the opposite: tenants arrive constantly, each is small, and every workspace needs the same schema at the same version. Running 68 migrations once per workspace turns a deploy into a fan-out job, and a failed fan-out leaves the fleet at mixed versions.
So Istova uses one schema with a tenant discriminator on every tenant-owned row, a single data-access layer that injects scope server-side, and row-level security as a second wall. The application cannot pass a tenant id by hand, and the database rejects a query that runs under the wrong scope.
The cost moves rather than disappears. Now every query is one forgotten filter away from a breach, so the defence is a scoped access layer plus negative tests that try to read another tenant’s rows on every path — including exports and vector queries, which are the paths people forget.
ALTER TABLE invoices ENABLE ROW LEVEL SECURITY;
ALTER TABLE invoices FORCE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation ON invoices
USING (tenant_id = current_setting('app.tenant_id', true)::uuid);
-- per request, inside the transaction
SET LOCAL app.tenant_id = '...';The rule I took from both
Tenancy is not a database feature you pick once. It is a decision about how many tenants there will be, how big each one gets, and how often the schema changes — and the answer can flip the design entirely.
Deltern: few tenants, large, schema changing weekly. Schema per tenant, isolation by structure, cross-tenant work done in code.
Istova: many tenants, small, schema changing constantly for everyone at once. Shared schema, isolation by policy, cross-tenant work for free.
Choosing the same model for both would have been consistency for its own sake. The expensive part is not the choice — it is discovering the choice was wrong two years in, when both the data and the customers are already there.