Skip to content
Bynarize Technologies home

SaaS and Enterprise

Multi-tenant SaaS architecture: shared database, schema or database per tenant

The trade-offs between the three common SaaS tenancy models, and how to keep tenant data isolated whichever you choose.

By Bynarize Engineering Team. Published . 8 minute read.

App

Every SaaS product serves many customers, called tenants, from one platform. How tenant data is separated is one of the earliest architectural decisions and one of the hardest to change later. It affects cost, performance, security reviews, data residency and how quickly you can onboard customers.

There are three common models. Most products should start with the first and keep the option of the others for specific customers.

Model 1: shared database, shared tables

All tenants share the same database and tables. Every tenant-owned row carries a tenant_id column, and every query filters by it.

Strengths

  • Lowest infrastructure cost per tenant.
  • One schema to migrate, one database to back up and monitor.
  • New tenants are just new rows, so onboarding is instant.
  • Cross-tenant reporting for your own operations is simple.

Risks

  • A missing filter in one query can expose another tenant's data.
  • One very large or very busy tenant can affect everyone else.
  • Some enterprise customers will ask for stronger isolation.

How to make it safe

  • Enforce the tenant filter in one place, such as a repository layer or ORM global filter, rather than trusting each query.
  • Add database-level protection. PostgreSQL row-level security policies keyed on a session variable make the database itself refuse cross-tenant reads.
  • Include tenant_id in composite indexes so tenant-scoped queries stay fast as data grows.
  • Write automated isolation tests that create two tenants and assert that every API endpoint refuses to return the other tenant's data.

Model 2: shared database, schema per tenant

Each tenant gets its own schema inside a shared database. Tables are identical across schemas.

Strengths

  • Stronger logical separation; a query cannot accidentally read another schema.
  • Per-tenant backup and restore is easier.

Risks

  • Migrations must run across every schema, which becomes slow and fragile with thousands of tenants.
  • Connection pooling and caching are more complex.
  • Database engines have practical limits on the number of schemas and objects.

This model works for products with tens or low hundreds of tenants, each relatively large.

Model 3: database per tenant

Each tenant has its own database, sometimes on dedicated infrastructure.

Strengths

  • Strongest isolation and the simplest story for security reviews.
  • Supports data residency: a tenant's database can live in a specific region.
  • Noisy neighbours are no longer a problem.

Risks

  • Highest cost per tenant.
  • Provisioning, migrations, monitoring and backups must all be automated across many databases.
  • Cross-tenant analytics needs a separate reporting pipeline.

The hybrid most products end up with

A practical pattern is to run most tenants in the shared model and offer isolated databases as part of an enterprise plan. For this to work, the application must resolve the tenant early in each request and look up where that tenant's data lives, instead of assuming one connection string.

That resolution step is worth designing on day one even if every tenant starts in the shared database:

  1. Identify the tenant from the subdomain, a token claim or a header.
  2. Look up the tenant's configuration: plan, entitlements, data location.
  3. Open the right connection and set the tenant context for the request.

Tenancy is more than the database

Isolation decisions also apply to:

  • File storage: prefix object keys by tenant and enforce it in the storage service, not just the UI.
  • Caches and queues: include the tenant in cache keys and message payloads.
  • Background jobs: a job processing one tenant must not be able to read another's data.
  • Search indexes and vector stores: filter by tenant on every query, ideally enforced by the index.
  • Logs: include the tenant identifier so support can trace issues, and avoid logging personal data.

Entitlements belong in data, not code

Plans change often. If features and limits are written as if (plan === "pro") checks scattered across the codebase, every pricing change needs a release. Instead, store entitlements per plan (and overrides per tenant) as configuration, and check capabilities rather than plan names. The billing integration then only needs to update which plan a tenant is on.

Decide with your commercial model in mind

Ask which customers you will sell to in the next two years. If they are small and mid-sized businesses, a well-protected shared model is right. If they are large enterprises in regulated sectors, plan for isolated databases early, even if the first customers share one.

Bynarize builds and operates its own multi-tenant product, Bynarize HRMS, and helps founders and software companies design tenancy, provisioning and billing for theirs. Read more about our SaaS product development and database engineering services.

  • SaaS
  • Multi-tenancy
  • PostgreSQL
  • Architecture

Have a business challenge or software idea?

Let's discuss your requirements and explore the right technology solution for your business.

Email
hello@bynarize.com
Phone and WhatsApp
+91 82629 95977
Response
Within one business day