Skip to content
RED SAGSkills
hardBackend Developer interview question

You are building a B2B SaaS backend used by many companies. How would you design multi-tenancy and make sure one tenant can never see another tenant data?

What the interviewer wants to hear

  • Models: shared tables with tenant_id, schema per tenant, database per tenant
  • Trade-offs in cost, isolation, migrations and noisy neighbours
  • Enforce tenant scoping centrally, e.g. row-level security or a data access layer
  • Tenant in auth token, never trusted from request body
  • Tenant-aware caching, logging, testing and backups

Model answer

There are three main models. Shared tables with a tenant_id column is cheapest and simplest to migrate, but a missing WHERE clause can leak data, and big tenants can be noisy neighbours. Schema per tenant gives more isolation but migrations across thousands of schemas are slow. Database per tenant gives the strongest isolation and easy per-tenant backups, which enterprise or compliance customers may require, but costs more to run. Many products use shared tables by default and dedicated databases for large customers. For safety, I would never rely on each developer remembering the filter. The tenant id comes from the verified auth token, not the request body, and is enforced centrally, for example with PostgreSQL row-level security using a session variable, or a repository layer that always adds it. Cache keys, file storage paths and search indexes must include the tenant, and I would add automated tests that try cross-tenant access.

Can you answer it under time pressure?

Take a timed hard round and get scored on every answer.

Start mock interview

More hard Backend Developer questions