liveBook · Manning

Table-level multitenancy

As explained in Crack Any Codebase with AI

A shared-table tenancy model stores multiple customers' records in common database tables and separates them with tenant-identifying columns and query predicates.

Table-level multitenancy stores multiple customers’ records in shared tables, then relies on tenant columns and application query predicates to keep rows separated. section 7.4

Treat the tenant boundary as an application responsibility:

  • Tag rows with identifiers such as userId, teamId, or organizationId. section 7.4
  • Apply the correct tenant predicate to every query; a missing condition can expose another customer’s rows. section 7.4
  • Track nested ownership carefully: newer organization membership can require checking more than one ancestor identifier. section 7.4
Table 7.4 Common database designs for multi-tenancy
Model
What isolates tenants
What it buys
What it costs
Single-tenant
One deploy per customer
Total isolation, trivial reasoning
No economy of scale; Cal.com's self-host story, not its cloud
Shared table, tenantId column
A WHERE userId/teamId = ? on every query
One database, one schema, cheapest to operate, what Cal.com runs
One missing WHERE is a cross-tenant leak; the DB won't stop you
Schema-per-customer
A Postgres schema namespace per tenant
Isolation without a fleet of databases; per-tenant backup
Migrations fan out across N schemas; connection-pool pressure
Database-per-customer
A whole database per tenant
Strong isolation, per-tenant scaling and residency
Heaviest ops; migrations and monitoring multiply by tenant count

Compare shared-table tenancy with single-tenant, schema-per-customer, and database-per-customer isolation models. section 7.4

Figure 7.6 In a shared table, the application enforces tenant isolation by adding WHERE teamId = ? to every query. Forgetting this clause leaks one tenant's private data to another.

Visualize the required tenant predicate and the failure mode caused by omitting it. section 7.4

How Crack Any Codebase with AI covers it

How deep it goes
Defines tenant columns, nested ownership, and leakage risks, but does not describe database-enforced isolation internals.
Examples
Uses Cal.com’s Team hierarchy, userId and teamId columns, and Profile organizationId as concrete scoping examples.
What it assumes
Introduces the tenancy choice through shared tables and contrasts it with stronger isolation models.
What you can do after
Evaluate tenant boundaries by inspecting ownership columns and verifying predicates across application queries.
How it connects
Connects tenant isolation with row-level scoping, schema-per-customer, and database-per-customer designs.

Also explained in

Compare how 2 books explain table-level multitenancy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Crack Any Codebase with AI. The section links point to the parts of the book it draws on.