One database for all customers, one schema each, or one database each?
Applications like this: B2B software where each customer is a company with its own users and data. This page is written the way I write a database design doc: the workload first, then where each kind of data goes and why, then how it grows, what breaks, and what I rejected.
| Dimension | This application |
|---|---|
| Writes | Varies by tenant. A few tenants usually produce most of the load. |
| Reads | Always inside one tenant. |
| Read to write | Typical application mix. |
| Consistency | Strict inside a tenant. Tenants never see each other's data. |
| Latency | Interactive. |
| Growth | By number of tenants, plus a few that grow very large. |
These incidents are why the choices below matter. Each one is written up with its numbers and sources.
Solid arrows: the application writes there. Dashed arrows: a copy fed from the source of truth (change data capture, an outbox, or a cache fill), which can be rebuilt from it.
| Data | Where it goes | Why |
|---|---|---|
| All tenants, shared tables | PostgreSQL or MySQL | One schema to migrate, one pool of connections, cheap to add a tenant. |
| Very large or regulated tenants | Their own database, same schema | Isolation of load and data, at the cost of more databases to operate. |
| Per-tenant settings and routing | A small catalog table | Says which database each tenant lives in. |
How each family of store behaves under traffic: Database families.
CREATE TABLE projects (
tenant_id bigint NOT NULL,
id bigint NOT NULL,
name text NOT NULL,
PRIMARY KEY (tenant_id, id)
);
ALTER TABLE projects ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation ON projects
USING (tenant_id = current_setting('app.tenant_id', true)::bigint);
-- the application sets the tenant at the start of each transaction
BEGIN;
SET LOCAL app.tenant_id = '42';
-- queries for this tenant run here
COMMIT;
Two tenants share one table. A policy adds the tenant filter to every query, so a query that forgets its WHERE clause still sees only its own rows.
SET ROLE app; SET app.tenant_id = '1'; SELECT * FROM notes;
SET app.tenant_id = '2'; SELECT * FROM notes;
INSERT INTO notes VALUES (1, 'Written by Globex into Acme');
RESET ROLE; SELECT * FROM notes;
Pick a stage, then throw something at it. The numbers are a model to show the shape of each change, not a measurement; the measured numbers are in the lab notebooks.
| What happens | What you see | What I do |
|---|---|---|
| A missing tenant filter | Data leak between customers | Row-level security, or a data layer that cannot build a query without tenant_id. |
| One tenant's heavy job | Every other tenant slows down | Rate-limit per tenant and move heavy tenants out. |
| Schema per tenant at thousands of tenants | Migrations take hours, catalog bloat | Prefer shared schema with tenant_id. |
Cost. Shared schema is the cheapest per tenant. Price large tenants that need their own database accordingly.
| Stage | Where it runs |
|---|---|
| Where I would start | Managed relational, shared schema |
| When it grows | Managed for the shared tier. Kubernetes with an operator, or many managed instances, for tenants that get their own database |
For a team without a dedicated database team. Who does which job in each option, and the full-cost comparison: Where to run the database.
The back-of-the-envelope numbers I would want before choosing anything. Move the assumptions to match your application. The link keeps your numbers, so a colleague sees the same ones.
Which database does my application need? What kind of application data goes in which database, and why, as design docs, plus the anti-patterns and the decisions behind them.