# Multi-Tenancy

> One app that serves many customers. Each one's data is kept apart.

**Field:** Software Development  
**Category:** Architecture  
**Also known as:** Multi-Tenant Architecture, Multitenancy, Multi-Tenant SaaS

## Think of it like

It is like a block of flats. Many families share one building, and each has its own locked door.

## Definition

Multi-tenancy means one copy of an app serves many customers and keeps their data apart. Each customer is called a tenant. All tenants share the same code and servers. Their data may share one database with a tenant ID on each row, or each may get its own database. Every query must filter by tenant, so no one sees the rest. Most apps sold as a service work this way.

## Example

Lucy's booking app serves 300 gyms from one database. Each table has a gym_id column, and each query checks it.

## Example code

```sql
SELECT * FROM bookings
WHERE gym_id = 42 AND day = '2026-11-17';
```

Every query names the tenant, here gym 42, so it only sees its own rows.

## Why it matters

Sharing one app keeps costs low and updates simple. Done badly, one client can see the data of another.

## Common mistake

Leaving out the tenant filter on one query. One missed line can show a customer the data of another. So check it in one place for all queries.

## Three principles

- **A shared app.** One copy for all.
- **Data kept apart.** By row, schema or database.
- **Filter everywhere.** Every query checks the tenant.

## Related terms

- [Software as a Service (SaaS)](https://learn.benibix.com/term/infrastructure/software-as-a-service)
- [Row-Level Security (RLS)](https://learn.benibix.com/term/data/row-level-security)
- [Authorization](https://learn.benibix.com/term/development/authorization)
- [Database](https://learn.benibix.com/term/development/database)
- [Scalability](https://learn.benibix.com/term/development/scalability)
- [Stateless Service](https://learn.benibix.com/term/development/stateless-service)

![Three gyms, A, B and C, all using one app on one server. Below the app, one bookings table has a gym id column. Rows for gym A, B and C are mixed in the table, and every query filters on the gym id so each gym sees only its own rows.](https://learn.benibix.com/diagrams/dev6-multi-tenancy.svg)

---

Source: https://learn.benibix.com/term/development/multi-tenancy
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
