Architecture: multi-tenant
This course studies multi-tenancy using an application that has a single tenant. It starts by measuring the schema: 33 tables, 13 with a user_id, and a shared catalog of nine tables. It compares row-level, schema-level and database-level isolation by migration cost, connections and leak risk. It maps which tables would need a tenant key, lists five places where tenant data leaks, and covers PostgreSQL row-level security. It ends with preparations that commit to no pattern and an ADR recording the single-tenant decision.
What you'll learn
- ✓The difference between a user_id and a tenant key
- ✓Row-level, schema-level and database-level tenancy and their trade-offs
- ✓Deciding table by table which tables get a tenant key
- ✓Five places where tenant data leaks, and PostgreSQL row-level security
- ✓When schema or database per tenant, or a hybrid, fits
- ✓Low-cost preparation and an ADR that choose no pattern
This application is not multi-tenant
Multi-tenancy is easiest to understand from an application that doesn't have it, because the gap is measurable.
Read the full lesson free →Curriculum
7 lessonsThis application is not multi-tenant
Measures a single-tenant schema and explains why a user_id differs from a tenant key when forgotten.
Three patterns
Compares row-level, schema-level and database-level tenancy by isolation, migration cost, connections and how each one leaks.
What row-level would cost here
Sorts the tables into shared, tenant-scoped and users, and covers denormalization, per-tenant indexes and default_scope problems.
The leak
Covers five places tenant data leaks, from a forgotten where to the console, and PostgreSQL row-level security.
Schema and database per tenant
Explains schema and database per tenant, their costs, the requirements that justify them, and the hybrid approach.
Preparing without deciding
Lists five preparations that commit to no pattern, what to avoid building early, and an ADR to write.
Putting it together: fifteen minutes
Reviews the measurements, the three patterns, the hybrid, the five leaks and the habits that prevent them.