Skip to main content

Multi-Tenancy

Pronunciation
MUL-tee TEN-un-see
Updated 3 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/multi-tenancy

In short

Multi-tenancy is an architecture in which one running system serves many customers, called tenants, while keeping each tenant's data and settings separate.

What is multi-tenancy?

In a multi-tenant system, a single deployment of an application serves many customers at once. Each customer, called a tenant, is usually an organization such as a company or a team, with its own users, data and settings, and each sees the system as if it were theirs alone. Most SaaS products work this way, much like an apartment building where the tenants share the structure, plumbing and power but each has a locked door.

The key design decision is how tenants share data. With a database per tenant, sometimes called the silo model, each tenant gets its own database: strong isolation, but more to run. With a shared schema, the pool model, every table has a tenant_id column and every query must filter by it, which is the cheapest option and scales to thousands of small tenants. A middle path gives each tenant its own schema in a shared database, and many products mix models, moving their largest customers into dedicated silos.

The biggest risk is a leak between tenants: one query that forgets the tenant filter can show a company's data to another. Teams guard against it by working out the tenant once per request, from the signed-in account or the subdomain, and enforcing the filter in one central place, for example with PostgreSQL's row-level security. The second classic problem is the noisy neighbor, a tenant whose heavy usage slows everyone else down, which is handled with rate limits, quotas and by moving heavy tenants to their own resources.

Multi-tenancy is often equated with SaaS, but they answer different questions. SaaS is how software is sold and delivered, as an online subscription; multi-tenancy is one way to build it, and a SaaS product can also be single-tenant, running a separate instance for each customer, usually at a higher price. Multi-tenancy also exists outside SaaS: public clouds run many customers' virtual machines on shared hardware, and companies share one Kubernetes cluster between teams.

Key takeaways

  • One deployment serves many tenants, each with isolated data and settings.
  • Data can be split per database, per schema, or shared with a tenant_id column.
  • A missing tenant filter can leak data, so isolation is enforced centrally.
  • Noisy neighbors are contained with rate limits, quotas and dedicated resources.
  • SaaS is a delivery model; multi-tenancy is an architecture often used to build it.

Example

Isolating tenants in a shared table with PostgreSQL row-level securitysql
-- One shared table: every row records which tenant owns it
CREATE TABLE invoices (
  id        bigserial PRIMARY KEY,
  tenant_id uuid NOT NULL,
  amount    numeric NOT NULL
);

-- The database adds the tenant filter to every query on this table
ALTER TABLE invoices ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation ON invoices
  USING (tenant_id = current_setting('app.tenant_id')::uuid);

-- Per request, the app (connected as a role that doesn't own the table) sets the tenant
SET app.tenant_id = '3f2b8c1e-5d4a-4c7e-9b1a-2e6f0d8c7a41';
SELECT * FROM invoices;  -- only this tenant's invoices, with no WHERE clause

Readers ask

What is the difference between single-tenant and multi-tenant?

In a single-tenant setup each customer gets its own instance of the application and database, which gives the strongest isolation and room for customization but costs more to run and update. In a multi-tenant setup customers share one instance, which is cheaper and updates everyone at once, but isolation has to be built into the software.

Is a tenant the same as a user?

No. A tenant is usually a customer organization, and it can have many users. In a project tracker sold to companies, each company is a tenant and its employees are its users.

Which multi-tenant database model should I choose?

A shared schema with a tenant_id column suits many small tenants and is the cheapest; a database per tenant suits fewer, larger tenants or strict compliance needs, such as keeping a customer's data in a particular country. Many products start with the shared model and move big customers to their own database later.

See also

Sources

Spotted a mistake or something missing on this page?Suggest an edit

More

Settings