Database per tenant: shared tables, schema per tenant or a database per user
Multi-tenant database design compared: a shared table with tenant_id, row-level security, schema per tenant and database per tenant, with dated limits.
CrabTalk Team
A multi-tenant service keeps every customer's data in one of four shapes: one shared set of tables with a tenant_id column, the same with row-level security enforced by the database, a schema per tenant, or a separate database per tenant. Shared tables pack the most tenants onto the least infrastructure and leave isolation to every query; a database per tenant isolates each tenant's data and used to cost the most to run. Per-tenant SQLite has changed that cost. This post compares the four on isolation, cost, migrations and who pays for each tenant's data, with sources and dated limits.
The four models
| Model | Where isolation lives | What a mistake looks like |
|---|---|---|
Shared tables, tenant_id column |
Every query in application code | A query without the filter returns other tenants' rows |
| Shared tables, row-level security | Database policies, per table | A policy that is too broad, or a role that bypasses it |
| Schema per tenant | Schema privileges and search_path |
A role with access to several schemas, or a wrong search_path |
| Database per tenant | The mapping from tenant to database | Routing a request to the wrong database |
Microsoft's multitenant storage guidance sums up the cost side: a shared database "provides the highest density of tenants to infrastructure", while with dedicated databases "each tenant's data is isolated from the others' data", and "The cost for this approach can be higher than shared hosting models."
Shared tables with a tenant column
Every table carries tenant_id, and every query filters on it. It is the default because it adds no infrastructure: one database, one migration run, one backup.
The risk is the query that forgets the filter. Nothing in the database stops it, and the bug returns real data from other customers. Busy tenants also share one database's resources, which Microsoft calls the noisy neighbor problem, "especially if you have tenants that are busy". And one tenant can't be restored alone: "restoring a single tenant might require you to restore the database to a separate resource."
Row-level security
PostgreSQL's row-level security moves the filter into the database. With it enabled on a table, policies decide which rows a role sees, and "If no policy exists for the table, a default-deny policy is used." Microsoft's Azure SQL guidance recommends it "as a database-enforced safeguard against cross-tenant data access."
A policy only filters to what it allows, so a too-broad policy still leaks. It also has exceptions:
- "Superusers and roles with the
BYPASSRLSattribute always bypass the row security system". - "Table owners normally bypass row security as well", unless the table is set to
FORCE ROW LEVEL SECURITY. An app that connects as the table owner gets no protection by default. - "Referential integrity checks ... always bypass row security."
Microsoft's storage guidance notes the cost in practice: "Many multitenant solutions don't use row-level security because of those complexities."
Schema per tenant
Each tenant gets its own schema of the same tables in one database. A schema is a namespace, not a wall: a role with privileges on several schemas can reach them, and a query resolved through the wrong search_path lands in the wrong tenant. Isolation depends on giving each tenant's connections a role limited to its schema. Tenants still share the server's resources, and a migration runs once per schema; frameworks such as django-tenants automate that. We cover running migrations across many tenants in Schema migrations across thousands of per-user databases.
Database per tenant
Each tenant gets a database of its own. When a connection can open only the selected tenant's database, a query can't reach another tenant's rows; SQLite itself can attach a second database file to a connection, so that boundary belongs to whatever opens the files. One tenant can be backed up, restored, exported or deleted on its own. The costs are operations: "It's important to use automated deployment approaches when you provision databases for each tenant" (storage guidance), and "The application must maintain a reliable mapping from each tenant identifier to its database" (Azure SQL guidance). Databases that share a server or an elastic pool still share its compute.
With server databases, each tenant database takes capacity on a server or pool, which made this the expensive option. When a database is a SQLite file, an idle tenant costs little more than its bytes:
| Platform | Databases | Per database | Source, date read |
|---|---|---|---|
| Cloudflare D1 | 1,000,000 per account on Workers Paid, the first 100,000 included | Up to 10 GB | D1 limits, November 25, 2026 |
| Cloudflare Durable Objects | Unlimited objects | Up to 10 GB per SQLite-backed object on Workers Paid | Durable Objects limits, November 25, 2026 |
| Turso | 100 on Free; unlimited on paid plans | Storage is a plan-wide allowance, with overage | Turso pricing, November 25, 2026 |
Cloudflare's D1 docs say it outright: D1 "is designed for horizontal scale out across multiple, smaller (10 GB) databases, such as per-user, per-tenant or per-entity databases." And Turso's pricing page: "Idle databases cost only storage, so a large fleet of mostly-idle databases stays cheap."
Who pays for each tenant's data
Who pays follows whose account holds the data, not which tenancy model it uses. When every tenant's data sits in the service's own cloud account, as it usually does, the service pays for every tenant's bytes, whether those tenants pay it or not, and a free tool's storage bill grows with every user it gains.
A database per tenant makes a different arrangement easy to build: each tenant's database can be held, and billed, on the tenant's own account.
Choosing
- Shared tables with
tenant_idfor internal tools and early products where every query goes through one data-access layer you control. - Row-level security when the data is relational, tenants are many and small, and you can connect as a role the policies bind.
- Schema per tenant when tenants need custom tables on shared infrastructure, and each tenant's connections can use a role limited to its schema.
- Database per tenant when tenants need their data isolated, restored, exported or deleted on their own, or when each tenant's data should be billed to them.
A database per caller on CrabTalk
CrabTalk's caller storage gives a service a separate SQLite database for each caller.
[storage.caller]
migrations = "caller"- The host picks the database. For each call it selects the database of the verified caller: the billed account, plus the end user when one is verified. Service code never passes a tenant ID, so there is no routing for it to get wrong. The first successful write creates the file. Members of an organization calling as the org, with no separate end user, share one database.
- The caller's plan holds it. Each caller's database counts toward the billed account's plan storage, so the service's own storage doesn't grow with its callers. The service's owner pays the compute of each call.
- The caller owns it. Callers download or delete their database from their account's Storage page, and it stays theirs after the service is deleted.
For the MCP side of the same question, see Where should an MCP server store per-user data?. The full guide is in Caller storage.