Architecture decisions · Performance and scale

Tenants of very different sizes in one system

A few large customers generate most of the load, one heavy job slows everyone, and a prospect asks how their data is kept apart from others'.

01

How it is diagnosed

Find which tenants and which tables carry the load, measure the others' p95 while the heaviest runs its job, and run one query as two tenants to see what comes back.

02

The options, side by side

Switch on a situation and see what each option does with it.

A

Shared database, rows tagged by tenant

The largest tenant runs its month-end jobThe others' median holds, but their slowest answers get slower, and those are the ones users feel.

A query is written without a tenant filterWith forced row-level security it still returns only that tenant's rows; without it, other tenants' rows.

A tenant leavesA verified export, personal data erased, accounting records kept until the retention date.

When it fits
Tenants are similar in size and cross-tenant queries are common.
Trade-offs
One heavy tenant slows everyone, and isolation has to be enforced below the queries.

B

A database per tenant

The largest tenant runs its month-end jobThe others do not feel it.

A query is written without a tenant filterIt can only see that tenant's database.

A tenant leavesAn export, then that tenant's database goes with it.

When it fits
Isolation must be physical and tenants are few and large.
Trade-offs
Cross-tenant queries become hard, and migrations, backups and monitoring multiply with every customer.

C

Hybrid: shared by default, a heavy tenant's lines in a database of their own

The largest tenant runs its month-end jobThe others are back to their baseline, because the heavy lines are in another database.

A query is written without a tenant filterThe policy holds in both databases.

A tenant leavesAs in the shared case, and its own database, if it has one, goes with it.

When it fits
Tenants differ a lot in size and most of the load sits in one large table.
Trade-offs
Two placements to run; moving a tenant is a verified copy and one routing change.

03

What decides between the options

How unevenly the load is spread, whether any customer requires physical separation, and whether some users work across tenants.

What decidesA Shared database, rows tagged by tenantB A database per tenantC Hybrid: shared by default, a heavy tenant's lines in a database of their own
One tenant's heavy job The other tenants should not feel it. limited The other tenants' slowest requests get slower: in the lab, their p95 rose almost eightfold. suits it Isolated: the other tenants do not feel it. suits it Isolated: once its lines move, the others are back to their baseline.
Where the boundary is enforced A security review asks, and the answer should be a test. needs work Row-level security and a two-tenant test. suits it Physical: separate databases. needs work Row-level security in both places, and the same test.
Users who work across tenants An accountant with many clients needs one list of deadlines. suits it One query, as a reviewed exception. limited One query per database, combined afterwards. suits it One query in the shared database.
What there is to run Every database is one more migration, backup and alert. suits it One database. limited One per customer. needs work Two, and the automation for more.
One tenant's heavy job A B C

The other tenants should not feel it.

  • A · Shared database, rows tagged by tenant limited The other tenants' slowest requests get slower: in the lab, their p95 rose almost eightfold.
  • B · A database per tenant suits it Isolated: the other tenants do not feel it.
  • C · Hybrid: shared by default, a heavy tenant's lines in a database of their own suits it Isolated: once its lines move, the others are back to their baseline.
Where the boundary is enforced A B C

A security review asks, and the answer should be a test.

  • A · Shared database, rows tagged by tenant needs work Row-level security and a two-tenant test.
  • B · A database per tenant suits it Physical: separate databases.
  • C · Hybrid: shared by default, a heavy tenant's lines in a database of their own needs work Row-level security in both places, and the same test.
Users who work across tenants A B C

An accountant with many clients needs one list of deadlines.

  • A · Shared database, rows tagged by tenant suits it One query, as a reviewed exception.
  • B · A database per tenant limited One query per database, combined afterwards.
  • C · Hybrid: shared by default, a heavy tenant's lines in a database of their own suits it One query in the shared database.
What there is to run A B C

Every database is one more migration, backup and alert.

  • A · Shared database, rows tagged by tenant suits it One database.
  • B · A database per tenant limited One per customer.
  • C · Hybrid: shared by default, a heavy tenant's lines in a database of their own needs work Two, and the automation for more.

04

What the work looks like

The step of the offer where a case like this usually starts:

03

Architecture assessment

Findings, risks, options and next steps, in writing. A good starting point when the scope is not yet clear.

See the service: Performance and scale →

05

Is this your case?

Send it with this problem already selected; the next page asks which options you considered and a little context. No verdict on your system: that only comes once I understand it.

Send this case →

Or write to me directly at contacto@danielcolaco.pt.