skip to content

One customer organization asks you to roll their data back to yesterday's state after a bad bulk import, and another asks for complete deletion of their data at the end of their contract. How does the multi-tenant storage layout - shared tables with a tenant_id column, one schema per tenant, or one database per tenant - change how you satisfy each request?

level: middleimportance: should knowfreq 32%

answer

  1. recovery unit = database, not tenant
  2. pooled: restore side copy, extract rows in FK order
  3. schema-per-tenant: dump one schema, swap it in
  4. db-per-tenant: point-in-time restore, DROP on exit
  5. backups outlive deletes -> retention or crypto-shred

basics

~20 s

With a database per tenant, restore that database to a point in time and drop it on exit. With schema per tenant, restore a side copy and dump or swap the one schema. With shared tables, restore the whole database to a side copy, extract that tenant's rows in dependency order and merge them back, and delete by cascading batched DELETEs.

solid answer

~50 s

**Database per tenant:** both requests are one operation - point-in-time restore of that database, and DROP DATABASE on offboarding. This is the strongest practical argument for siloing. **Schema per tenant:** restore the instance to a side copy, dump that one schema, swap it in; deletion is DROP SCHEMA. Cheap enough, though recovery still starts from an instance-wide backup. **Shared tables:** there is no per-tenant recovery unit. You restore the entire database to a side copy at the target time, extract that tenant's rows, and merge them back in foreign-key order while deciding what to do with rows changed since. Deletion is a fan-out of DELETEs across every tenant-owned table, in dependency order, batched to avoid long locks - and it leaves bloat behind. In every layout, deletion also covers replicas, backups still inside their retention window, search indexes, caches, object storage and logs. Crypto-shredding a per-tenant encryption key is the usual answer for data already sealed into backups.

go deeper

for a junior

Explain that backups restore a whole database, so a single customer is easy to restore only when they have their own database.

for a middle

Walk through each layout's procedure, including the side-copy-plus-extract flow for shared tables and DROP for schema or database per tenant.

for a senior

Add batching to avoid locks, foreign-key and sequence collisions on merge, bloat after mass deletes, derived-store deletion, and crypto-shredding for backups.

for a principal

Treat per-tenant recoverability and erasure as requirements that drive the tenancy model and its pricing tiers, and mandate export/import tooling that doubles as the tenant-migration path.

## The idea: what is the recovery unit? Backups and point-in-time recovery operate on a **database or instance**, not on a customer. Whether "restore one tenant" is easy therefore depends on whether the tenant *is* a recovery unit. This is where the tenancy models differ most sharply in daily operations, and it is a question interviewers use because it exposes whether a candidate has actually run a multi-tenant system. ## Restoring one tenant **Database per tenant.** The tenant is the recovery unit. Restore that database to the requested timestamp with ordinary point-in-time recovery; nobody else is affected, and the tenant can even have its own backup schedule and retention. Simple and fast to reason about. **Schema per tenant.** The recovery unit is the whole instance, so: restore a copy of the instance to the target time (typically into a temporary instance), export the single tenant's schema from it, then swap it into production - rename the damaged schema aside, load the recovered one, verify, drop the old. Downtime is confined to that tenant. The cost is one full restore per request: fine at low frequency, painful weekly. **Shared tables.** Hardest. Restore the whole database to a side copy at the target time, then extract that tenant's rows from every tenant-owned table and merge them back into production. The details are where it goes wrong: rows must be inserted parents-before-children to satisfy foreign keys and removed in the reverse order; sequences and surrogate ids may collide with rows created since; you must define the semantics of legitimate changes made *after* the bad event; and the operation must not lock tables for other tenants, so it runs in batches. This is why teams running pooled tables build a **tenant export/import tool** early - the same tool serves restore, offboarding export, and moving a tenant to another database. A cheaper mitigation for the common cause (a bad bulk import) is application-level soft delete or versioned import batches, so an import can be reverted logically without touching a backup at all. ## Deleting one tenant **Database per tenant:** drop the database, revoke its credentials, remove it from the routing directory. **Schema per tenant:** drop the schema, which removes its tables in one statement. **Shared tables:** DELETE from every tenant-owned table in dependency order, or rely on cascading foreign keys from a tenant root row, batched by key ranges with frequent commits so you neither hold long locks nor build one enormous transaction. Expect table and index bloat afterwards, requiring vacuum or reorganization to release space. Partitioning by tenant, where it fits, turns this into a metadata operation, but for tens of thousands of small tenants that is usually impractical. ## What every layout still owes you Deletion requests - contract exit, or a legal erasure request - are not satisfied by removing live rows alone: - **Backups** taken before the deletion still contain the data, and you cannot surgically edit them. The accepted answers are to let the documented retention window expire, or **crypto-shredding**: encrypt each tenant's data under a per-tenant key and destroy the key, rendering every copy unreadable. - **Replicas and standbys** apply the deletion automatically, but logical copies - analytics warehouse, data lake, search index - need their own deletion path. - **Derived and external stores:** caches, object storage, exported reports, message queues, and audit or application logs holding tenant payloads. - **Ordering and proof:** run deletion as a tracked job with a per-store checklist, producing an artifact you can show the customer or an auditor. ## The interview-worthy summary The restore and delete story is a first-class input to the tenancy decision, not an afterthought. If per-tenant recovery is a contractual promise or a frequent support request, that pushes hard toward a database per tenant - or toward pooled tables *plus* a purpose-built export/import tool and soft-delete semantics that make the common cases recoverable without touching a backup.

  • A customer invokes a legal right to erasure, but their data sits inside backups you cannot edit. What do you do?
    Delete from all live and derived stores immediately, then use one of two accepted approaches for backups: document that those copies age out within a defined retention window and cannot be restored into production without a re-deletion step, or use crypto-shredding - encrypt each tenant's data under a per-tenant key so destroying the key renders every copy, including backups, unreadable. Either way, record it as an auditable tracked job with a per-store checklist.
  • Why is merging a restored tenant back into shared tables riskier than swapping a schema?
    Because you are writing into tables other tenants are actively using: inserts must respect foreign-key order, surrogate keys and sequences can collide with rows created since the restore point, and you must define what happens to legitimate changes made after the bad event. It also has to run in batches so it does not hold locks that stall other tenants, whereas a schema swap is a namespace-level operation affecting only that tenant.

saying these in an interview costs you the question

  • Assuming point-in-time recovery can target a single customer inside shared tables
  • Forgetting that backups within the retention window still contain 'deleted' tenant data
  • Deleting a tenant's rows in one huge transaction and locking the tables for everyone
  • Ignoring derived stores - search index, cache, warehouse, object storage, logs
  • Restoring rows without respecting foreign-key order or surrogate-key collisions

context