Skip to content

Costly per-tenant databases and the risk of cross-tenant data leaks

SaaS multi-tenant architecture with Row Level Security

Move to a pooled PostgreSQL design where Row Level Security enforces tenant isolation in the database, cutting per-tenant overhead and the risk of a missed WHERE clause.

Symptoms

Signs your platform has this problem

If several of these sound familiar, the plan below is where we would start.

01

Hundreds of tenant databases

Schema migrations taking hours and complex orchestration across separate databases.

02

Cross-tenant leak risk

Relying on WHERE tenant_id clauses that are easy to forget in complex joins.

03

High hosting costs

Paying for dedicated instances for small, low-traffic tenants.

Remediation plan

How we fix it, step by step

Each phase ends with a measurement, so you can see what changed before the next one starts.

01

Schema consolidation

Designing pooled PostgreSQL schemas with a tenant_id foreign key on every tenant table.

02

Row Level Security

Database policies that filter every query to the current session's tenant.

03

Tenant context and pooling

Middleware that sets the tenant (SET LOCAL app.tenant_id) on each transaction, through a pooler such as RDS Proxy.

04

Automated permission tests

pgTAP test suites that check no query can read or write across tenant boundaries.

Technical checklist

Remediation checklist

What we check before a change goes to production:

  • Consolidate tenant databases into a pooled PostgreSQL cluster
  • Enable FORCE ROW LEVEL SECURITY on every multi-tenant table
  • Set the tenant context per transaction through the connection pooler
  • Run pgTAP permission tests in CI

What we measure

We take a baseline first and report the same measurements after each change, from your own monitoring — evidence, not promised results.

Database cost
Per-tenant databases vs the pooled cluster, monthly
Isolation tests
Tables covered by automated cross-tenant tests
Migration time
Time to apply a schema change across all tenants

Related service

Custom software

Custom software for Indian SMEs and startups, built around your workflow with an agreed scope, review milestones, clear ownership and documented handover.

Explore Custom software

Questions

Questions about this remediation

A pooled database with PostgreSQL Row Level Security is far cheaper to run across many tenants and turns schema migrations into a single operation. Isolation moves from separate databases to database-enforced policies, which you test automatically.

With a hybrid silo-and-pool model: high-tier enterprise customers get dedicated database clusters, while standard tiers share the pooled cluster.

Want an engineer to look at this with you?

Send us the symptoms and any metrics you have. We'll reply within one business day, set up a call and agree what to measure before anything changes.