100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
API Security
32 minintermediate

Multi-Tenancy and Data Isolation

A multi-tenant API serves many separate customers — companies, teams, or organisations, usually called tenants — from one shared codebase and, almost always, one shared database. That sharing is what makes multi-tenant systems economical to run: one deployment, one schema, one set of servers, instead of provisioning a separate stack per customer. It's also exactly why a single missing check can be catastrophic in a way a single-tenant system's equivalent mistake isn't — every query in a multi-tenant system touches a table holding every tenant's data at once, and the only thing standing between tenant A's request and tenant B's rows is whichever code path is supposed to filter by tenant.

This is BOLA's tenant-scale cousin, and the two are worth distinguishing precisely: BOLA is about one object belonging to the wrong user; a multi-tenancy isolation failure is about an entire tenant's data — every object, every table, potentially every row an attacker's queries can reach — becoming visible to a different tenant because the isolation boundary itself, not just one object's ownership check, was never enforced. The blast radius of a BOLA bug is one object; the blast radius of a tenant isolation failure is an entire customer's data, and often every customer's data at once.

The core discipline is making tenant scoping impossible to forget rather than merely correct when someone remembers it: every query that touches tenant-owned data should be structurally incapable of returning another tenant's rows, whether through database-level enforcement, an application-layer scoping requirement baked into the data-access layer, or — for the highest-sensitivity cases — physical separation at the database or schema level.

This lesson covers the spectrum of isolation strategies from cheapest to most rigorous — shared schema with a tenant-ID column, schema-per-tenant, and database-per-tenant — and the specific, structural techniques (row-level security, connection-level tenant context, mandatory scoping in the ORM) that make the cheapest option, the one almost every growing system actually uses, trustworthy rather than merely convenient.

Analogy🏏Cricket
🏏 Think of it like cricket: A large sports complex hosts several different clubs' training sessions on the same day, sharing one set of nets, one equipment store, and one set of changing rooms rather than each club building its own separate facility — cheaper for everyone, and perfectly workable, provided the shared facility actually enforces which club's kit bag belongs in which locker and which club's session is booked into which net at any given hour. A complex that shares facilities but has no reliable way to tell one club's booking from another's isn't really running several separate sessions at all — it's running one session where anyone can wander into anyone else's net, use anyone else's kit, and read anyone else's team sheet left on a bench, purely because the shared-facility model was adopted without the enforcement that makes sharing safe. Multi-tenancy is the shared complex; tenant isolation is the enforcement that makes 'shared' mean 'efficiently shared' rather than 'accidentally merged.'
Lesson 11 of 35
0% complete