Database per tenant or shared schema: where each one fails.

Database per tenant vs shared schema is a choice about where a mistake lands. With shared tables, one table left without its rule can expose every customer at once. With a database each, the same mistake stays inside one customer's data, and you pay for that in migrations and connections. Harness, our open-source Rust backend, gives every backend its own database. This is the trade, with its limits.

By Nick van der Meij · Published

Listen to this post

A wall of numbered safe deposit boxes, each with its own lock.
Photo: Fixedsun, Wikimedia Commons, public domain (CC0), cropped and recoloured.

In short

  • Microsoft's guidance is blunt about shared tables: a multitenant database necessarily sacrifices tenant isolation.
  • A scan of 1,645 apps built on one AI app builder found 170 with inadequate row-level security, according to the researcher who ran it.
  • Cloudflare designed D1 for many small databases. Each is capped at 10 GB, and a paid account includes 100,000 of them.
  • Harness gives each backend one database today. Separate databases for the customers inside one backend are designed and unbuilt.

§1 · Models

Two models, and what the cloud vendors call them.

In the shared model every tenant's rows sit in the same tables, and a tenant column plus a rule decides who may read which row. In the separate model each tenant has a database, and a query runs against only that one. AWS calls these pool and silo. Microsoft's Azure SQL guidance describes several patterns between the extremes.

QuestionShared tablesA database per tenant
Isolation“A multitenant database necessarily sacrifices tenant isolation.”Single-tenant databases give “strong tenant isolation.”
Cost“In general, multitenant databases have the lowest per-tenant cost.”Each database carries its own resources. On Azure, elastic pools share them across databases.
A busy tenantIt carries “an increased risk of encountering noisy neighbors.”The load stays in that tenant's database.
Schema changesOne schema to change.The same change runs once per database, and some of those runs will fail partway.

The quotations are from Microsoft's page on tenancy patterns. Neither column wins outright. The rest of this post is about what each one costs when something goes wrong.

§2 · Shared

How a shared schema fails.

The standard tool for shared tables in Postgres is row-level security. You enable it on a table and write policies, and every row a query touches must pass one. It has real advantages: one schema to migrate, one connection pool, and analytics across all tenants in a single query.

Its weakness is that it fails silently. Supabase's own documentation carries the warning: “A table in an exposed schema without RLS is readable and writable by any role with a grant on it.” A new table where row-level security was never switched on raises no error, and neither does a policy that is too broad. The query runs and returns other tenants' rows. (A table with row-level security on and no policy at all is the safe case: Postgres then shows no rows.) The PostgreSQL manual adds a second trap. Superusers and roles with BYPASSRLS always skip the policies, and table owners normally do too.

One public scan has put numbers on this. In 2025 a researcher scanned apps generated by Lovable, an AI app builder whose generated sites store their data in Supabase.

  • 1,645generated projects analysed
  • 170projects with inadequate row-level security, about 10.3%
  • 303exposed endpoints across those projects
From Matt Palmer's statement on CVE-2025-48757. The CVE record scores it 9.3, critical, and notes that the supplier disputes it, on the ground that each customer is responsible for protecting their own application's data.

Those are one researcher's figures about one product, and the dispute is fair to mention. The pattern is still worth keeping in mind. Row-level security is correct only when every table has it switched on with the right policy, and a new table starts with it off.

§3 · Separate

How a database per tenant fails.

A database each moves the cost somewhere else. Every schema change now runs once per tenant, and some of those runs will fail halfway. Each database needs its own connection handling. A report across all tenants becomes a job that visits every database. On a platform that bills each database for compute, the bill grows with the tenant count even when most tenants are idle.

The last cost depends on the platform, and it is why SQLite services have made the model practical again. Cloudflare says so in its limits page: “D1 is designed for horizontal scale out across multiple, smaller (10 GB) databases, such as per-user, per-tenant or per-entity databases.” D1 bills rows read, rows written and storage, and its pricing page says you are not billed for hours or capacity units.

The ceiling is real, though. A D1 database stops at 10 GB. It is single-threaded, so by Cloudflare's own arithmetic a database whose average query takes 1 ms tops out at about 1,000 queries a second. A tenant that outgrows either number needs a different database.

§4 · Harness

What Harness does, and what it does not do yet.

Harness chose the separate model at the start and wrote the decision down. On Cloudflare a backend is one Worker with one D1 database. A module receives a handle to that database and no other, so no code path leads from one backend to another backend's rows. This part is Shipping.

How far one missing rule reaches in each model On the left, one shared table holds rows for three tenants, and a missing policy exposes all of them. On the right, three backends each have their own database, and a mistake in one stays inside that one. SHARED TABLES one database rows of tenant A rows of tenant B rows of tenant C A missing policy on one table exposes every tenant in it. A DATABASE EACH Atablesmigrations Btablesmigrations Ctablesmigrations A mistake in backend B stays inside B's database.
The highlighted outline is what one mistake can reach. The backends on the right share no table, so no cross-tenant policy exists to get wrong.

If you run one backend per customer, that is a database per customer today. Many products want something else: one backend whose customers each get a database inside it. That is Designed in a public epic (#23) and unbuilt. The native runtime, which runs the same modules on Postgres, serves one backend per process today. Its many-tenant layer with a separate control database is an accepted decision record and not code. The isolation page has the design in full.

§5 · Limits

What a database boundary does not solve.

It does nothing for two users of the same tenant. Deciding that a member may read an invoice and a guest may not is ordinary authorisation, and you still write it.

It is the wrong shape for a product whose value is shared data. A marketplace needs buyers and sellers in the same tables.

It makes fleet-wide questions slower to answer. Counting active users across four hundred databases is four hundred queries and a place to add them up.

And it inherits the platform's ceiling. On D1 that is 10 GB and one thread per database. Harness keeps an exit for that case, since every module's tests run on both SQLite and Postgres. The move is still work you would have to plan.

Where Harness sits among the other open backends is in An open-source Rust backend, next to Supabase and Firebase.

Questions

Questions people ask about this.

Is row-level security unsafe?
No. Postgres row-level security works, and many production systems run on it well. The weakness is in how it fails. A table where it was never switched on raises no error. On an exposed table without row-level security, Supabase's documentation says the table is readable and writable by any role with a grant on it.
How many D1 databases can one account hold?
Cloudflare's limits page says 1,000,000 on the Workers Paid plan, with the first 100,000 included and $0.10 a month for each one above that. The Free plan allows 10. Each database is capped at 10 GB on the paid plan.
Does a database per tenant cost more?
On most platforms it does, because each database holds compute. Microsoft's guidance says multitenant databases generally have the lowest per-tenant cost. D1 is billed differently: by rows read, rows written and storage, with no charge for hours. An idle database costs its storage.
When is a shared schema the better choice?
When tenants need to see each other's data, as in a marketplace or a social product. Also when you want analytics across every tenant in one query, or when one team must change a single schema quickly. Shared tables are simpler to operate, and that counts.

Sources

Where the numbers come from.

  1. Multitenant SaaS database tenancy patterns, Microsoft. Read on 30 November 2026.
  2. Silo, pool and bridge models, SaaS Lens, Amazon Web Services. Read on 30 November 2026.
  3. Row security policies, PostgreSQL documentation.
  4. Row Level Security, Supabase documentation. Read on 30 November 2026.
  5. Statement on CVE-2025-48757, Matt Palmer, May 2025. The scan figures are the researcher's own.
  6. CVE-2025-48757, CVE Program, 30 May 2025. The record notes that the supplier disputes it.
  7. D1 limits, Cloudflare. Read on 30 November 2026.
  8. D1 pricing, Cloudflare. Vendor list prices, read on 30 November 2026.
  9. ADR 0003: Compile-time composition, one Worker per venture, Cratefield, 5 September 2026.
  10. ADR 0008: The native runtime serves many tenants, one database each, Cratefield, 6 September 2026.

Keep reading

Get started with Harness Read the source