1.Tenancy models: shared schema, separate schema, separate database
A multi-tenant system has to decide, per resource, how much of the database each tenant shares with every other tenant. Shared database/shared schema puts every tenant's rows in the same tables, distinguished only by a tenant_id column. Shared database/separate schema still uses one database instance but gives each tenant its own schema (its own set of tables inside that instance). Separate database gives each tenant an entirely distinct database, sometimes on its own host. Each step trades lower operational cost for weaker isolation, so the right choice depends on what a single tenant's data leak or one tenant's heavy load is allowed to cost the others.
Key features
- Shared schema needs a tenant_id (or tenant_id-derived) filter on every single query touching a shared table — the database itself does not know tenant boundaries exist
- Separate schema isolates the tables but still shares the database engine, connection pool, and host resources — one tenant's runaway query can still starve others on the same instance
- Separate database is the only model where a full instance restore, a schema migration gone wrong, or a resource-exhaustion incident is naturally contained to one tenant
- Cost per tenant runs the opposite direction from isolation: shared schema is cheapest to run at scale (one set of tables, one connection pool), separate database is the most expensive (idle capacity reserved per tenant, migrations run N times)
- Real systems often mix models — most tenants on a shared schema, with an enterprise tier or a regulated tenant promoted to its own schema or database as a contractual or compliance requirement
Three tenancy models compared
- Shared schema (weak isolation, low cost)
- One tenants table, one tickets table, one everything table
- Only a WHERE tenant_id = ? clause keeps rows apart
- One connection pool and one migration for every tenant at once
- Separate database (strong isolation, high cost)
- Each tenant's tables live in a database only that tenant's connection can reach
- A missing WHERE clause cannot leak another tenant's rows — there is nothing to leak into
- N databases to provision, back up, migrate, and monitor instead of one
Command
Shared schema: one DB, one schema, tenant_id column on every table
Separate schema: one DB, N schemas, one set of tables per schema
Separate DB: N databases, one set of tables per databaseShared schema is cheapest but leans entirely on application code getting every tenant_id filter right; separate database is the only model where a mistake structurally cannot cross tenant boundaries. Isolation strength and operational cost move in opposite directions, and the choice can be made per tenant, not just once for the whole product.