# Multi-tenancy

> One running system serving many customers, each seeing only its own data.

- Level: Intermediate
- Topics: Cloud
- URL: https://tidbit.legios.com.ar/multi-tenancy/
- In Spanish: [Multi-tenancy](https://tidbit.legios.com.ar/es/multi-tenancy/)

**Multi-tenancy** is a design where a single installation of software, with its servers and databases, serves many customers at once. Each customer is a **tenant**. When a thousand companies use the same project management app, they are almost always on the same system, yet each one only sees its own projects and users.

It is what makes SaaS affordable: the provider runs and updates one system instead of a thousand, and spreads hardware costs across everyone. The cloud itself is multi-tenant too: your virtual machine may share a physical server with strangers' machines, kept apart by the hypervisor.

The hard part is isolation. Every query must be filtered by tenant, because one bug that forgets the filter can show one company's data to another. There is also the **noisy neighbor** problem: one tenant running a huge report can slow everyone down. Designs range from all tenants in shared tables with a `tenant_id` column, to a separate database per tenant, to a fully separate copy for big customers, which is called **single-tenant**.

## An analogy

An apartment building. Everyone shares the foundation, the elevator and the water pipes, which keeps rent low, but each apartment has its own lock. A loud party upstairs is the noisy neighbor.

## Keep in mind

- One system, many customers (tenants), each isolated from the others.
- Shared infrastructure is what makes SaaS and the cloud cheap to run.
- A missing tenant filter can leak data between customers.
- Isolation can be a column, a separate database or a separate deployment.

## Go deeper

- [Multitenancy on Wikipedia](https://en.wikipedia.org/wiki/Multitenancy)

## Related terms

- [Server](https://tidbit.legios.com.ar/server/): A computer whose job is to answer requests from other computers, all day, every day.
- [Database](https://tidbit.legios.com.ar/database/): An organized store of data that programs can search and update safely.
- [SaaS, PaaS and IaaS](https://tidbit.legios.com.ar/saas-paas-iaas/): Three ways to rent computing, depending on how much of the work you hand over.
- [Cloud computing](https://tidbit.legios.com.ar/cloud-computing/): Renting computers over the internet instead of buying your own.
- [Virtual machine](https://tidbit.legios.com.ar/virtual-machine/): A complete computer made of software, running inside a real one.
- [Hypervisor](https://tidbit.legios.com.ar/hypervisor/): The software layer that splits one physical computer into many virtual machines.
- [Bug](https://tidbit.legios.com.ar/bug/): A mistake in software that makes it behave differently from what was intended.
- [Deployment](https://tidbit.legios.com.ar/deployment/): Getting a new version of software from the team's computers to real users.
