One backend can serve many customers. Each request still needs a tenant. In a billing app, signing in proves who you are. Before opening an invoice, the API also has to check that it belongs to a company you can access.

Three ways to organise the data

  • Database per tenant. Restoring one customer’s data is easier. There are more databases to migrate and monitor.
  • Schema per tenant. The database is shared, but each tenant has its own set of tables. Migrations have to run across the schemas.
  • Shared tables. There is one set of tables to migrate. Every read and write has to remain within the right tenant.

A simple isolation test

Sign in as Customer A and request Customer B’s invoice. The API should deny access. Run the same check against updates and deletions, because tenant isolation applies to writes as well as reads.

The storage model changes the operational trade-offs. The obligation to identify the tenant and enforce its access rules stays the same.