Multi-tenancy
Pick how far apart customers' data lives, carry the tenant into every job, file and log, and restore, export or delete one tenant alone.
- Required 2
- Recommended 5
- Optional 2
Required
Run every background job inside its tenant
DAT-68Put the tenant ID in every job's payload, and make the worker set the tenant context before it touches data. A job without a tenant ID fails at once.
Delete every copy of a tenant when the contract ends
DAT-72When a customer leaves, return or delete their data in every store within the period your contract states. Backups holding it expire on their normal schedule.
Recommended
Choose the isolation model before the first customer
DAT-67Write down where each customer's data lives, in shared tables, a schema per tenant or a database per tenant. Record the reason and the tenant count it must reach.
Keep files and search indexes apart by tenant
DAT-69Store each tenant's files under a path that starts with its tenant ID. Filter every search and vector query by tenant on the server, inside the query.
Put the tenant on every log line and trace
DAT-70Add the tenant ID as a field to every log entry, trace and metric written while serving a tenant. Never put the tenant's name or data in that field.
Restore and export one tenant alone
DAT-71Keep a tested script that exports one tenant's data from every store, and one that restores a single tenant from backup without changing other tenants.
Find and contain noisy neighbours
DAT-73Measure database time per tenant, and give each tenant its own query time limit and job share. Move a tenant that uses more than a quarter of the database time to its own resources.
Optional
Give each tenant its own encryption key when customers ask to hold it
DAT-74When customers ask to hold their own key, encrypt each tenant's sensitive data with a data key wrapped by a key per tenant. Let a customer's key live in their own key service account.
Pin each tenant's data to its region
DAT-75When a customer's contract names a region, store the region on the tenant and keep its database rows, files, backups, logs and search indexes there.
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/data/multi-tenancy">Agent Wranglers data and databases playbook</a>. In code you write, add a comment next to it with the same link.