Understanding Multi-Tenancy: What It Actually Means in Practice
1. Introduction: What is Multi-Tenancy, Really?
I’ve always heard people talk about multi-tenancy, but for the longest time, it felt like one of those buzzwords that companies throw around—like "enterprise-grade" or "scalable architecture"—without actually explaining what it means.
So, I finally sat down to figure it out. What exactly is multi-tenancy, and why does it matter?
At its core, multi-tenancy (usually) refers to a single application that serves multiple customers (tenants) while keeping their data isolated.
Does Multi-Tenancy Always Refer to the Data?**
No! Multi-tenancy can apply to:
- The database (one DB per tenant, schema per tenant, or row-level)
- The application (one Go app handling all tenants, or separate instances per tenant)
- The infrastructure (separate compute resources, like per-tenant EC2 instances, containers, or Kubernetes pods)
Since most people usually refer to data multi tenancy, we will start by covering that first.
Data Multi-Tenancy
The Three Main Types of Data Multi-Tenancy**
There are multiple ways to implement multi-tenancy, each with different trade-offs:
Multi-Tenancy Approach | How It Works | Pros | Cons |
---|---|---|---|
Database-per-Tenant (Separate Databases) | Each customer gets their own database within the same instance or across instances. | ✅ Strong isolation ✅ Easier data migration per tenant | ❌ Higher resource usage ❌ Harder to manage at scale |
Schema-per-Tenant (Shared DB, Separate Schemas) | One database, but each tenant has a dedicated schema (tenant1.users , tenant2.users ). | ✅ Better isolation than row-level ✅ Scales better than per-db | ❌ Harder to manage schema changes ❌ More complex migrations |
Row-Based Multi-Tenancy (Shared DB, Shared Schema) | All tenants’ data is in the same tables, with tenant_id as a key. | ✅ Most scalable ✅ Simplest to manage at scale | ❌ Harder to enforce isolation ❌ Risk of data leaks |
Each of these models has use cases where it makes the most sense.