The Challenge
The platform was built for a single customer: hardcoded config, one shared database, and no concept of a tenant boundary anywhere in the codebase. Sales had already closed the next fifty customers before engineering had a plan for keeping their data apart. The brief was blunt: take the thing that works for one customer and make it work for fifty, without the fifty-first customer noticing a migration happened at all - and a rewrite, given eighteen months of production history behind it, was never on the table.
The Approach
- Replaced hardcoded config with a per-tenant settings table, rolled out behind a dual-read flag so nothing broke mid-migration
- Enforced tenant isolation with PostgreSQL row-level security instead of a database-per-customer model, keeping ops overhead flat as the tenant count grew
- Added a tenant-aware caching layer so one customer’s traffic spike couldn’t degrade another’s
The Result
- 50+ tenants onboarded onto the shared platform within two quarters
- Zero cross-tenant data incidents since launch
- Infrastructure cost per tenant down roughly 60% versus the one-database-per-customer model it replaced
What almost went wrong
The row-level security policies were the easy part to write and the hardest part to trust. A policy that looks airtight in a psql session can still leak if a connection pool reuses a session without resetting app.current_tenant between requests - a subtle enough bug that it only shows up under concurrent load, not in a single-threaded smoke test. Catching it meant writing a load test that specifically interleaved two tenants’ requests on the same connection pool and asserting that tenant A’s queries never once returned tenant B’s rows, not just checking that they usually didn’t.
Where it landed
Fifty-plus tenants now share the platform that was built to assume there’d only ever be one. None of them know that, which was the actual goal - the migration’s success metric was never “did we ship multi-tenancy,” it was “did any existing customer notice.”