- Multi-tenancy is not a single pattern — it is a spectrum from shared-everything to isolated-everything, and the right point depends on your compliance requirements, performance needs, and operational capacity.
- Data isolation is the hard problem. Compute isolation is relatively straightforward; ensuring one tenant can never access another tenant’s data requires discipline at every layer.
- We use row-level security with tenant context propagation as our default pattern, with dedicated database schemas for tenants with stricter compliance requirements.
Context
Every SaaS product Logicbric builds is multi-tenant. PMS serves multiple property management companies from a shared platform. Yezda screens candidates for multiple security firms. Downstream ERP manages operations for multiple oil and gas companies. The multi-tenancy decisions we make at the architectural level determine our cost structure, our security posture, our scalability, and the complexity of our operational burden.
This playbook captures the patterns we have settled on after iterating across multiple products and the decision framework for choosing between them.
Choose your isolation model
The three canonical models are: shared database with row-level tenant isolation, shared database with per-tenant schemas, and dedicated databases per tenant. Each sits at a different point on the cost-isolation trade-off curve. Shared-everything is cheapest to operate but requires the most careful engineering to prevent data leakage. Dedicated-everything is the most isolated but multiplies your operational burden and cost by the number of tenants. Our default is row-level isolation with tenant-scoped queries, upgrading to per-tenant schemas for clients in regulated industries.
- Assess regulatory requirements: some industries mandate physical data separation
- Estimate tenant count at scale — dedicated databases become unmanageable above 50-100 tenants
- Evaluate performance isolation needs: can one tenant’s heavy query affect others?
- Document your isolation model as an architectural decision record (ADR)
- Plan for migration between models — start shared, offer dedicated as an enterprise tier
Implement tenant context propagation
The most common source of multi-tenant data leakage is a missed tenant filter. A developer writes a query, forgets the WHERE tenant_id = clause, and suddenly one tenant can see another’s data. The solution is to propagate tenant context automatically through every layer of the stack. The authenticated user’s tenant ID is set once at the API gateway and flows through middleware, service layer, and database queries without any developer needing to remember to include it.
- Implement tenant context middleware that extracts tenant ID from the authenticated session
- Use database-level row security policies (PostgreSQL RLS) as a defence-in-depth measure
- Configure ORM-level default scopes that automatically apply tenant filters to all queries
- Build CI checks that flag any database query without a tenant filter
- Run cross-tenant access tests in your integration suite — attempt to access data as the wrong tenant
Design for noisy neighbour protection
In a shared infrastructure model, one tenant’s usage spike can degrade performance for all others. A property management company running a large end-of-month billing batch should not slow down another company’s real-time tenant portal. We implement noisy neighbour protection through per-tenant rate limiting, queue-based workload isolation for batch operations, and connection pooling with per-tenant quotas.
- Implement per-tenant rate limits on API endpoints
- Use separate worker pools for batch and real-time workloads
- Monitor per-tenant resource consumption and alert on anomalies
- Implement connection pool quotas to prevent one tenant from exhausting database connections
- Design background jobs to be tenant-fair — round-robin across tenants rather than processing one tenant’s backlog before starting another’s
Build tenant lifecycle management
Multi-tenant systems need robust processes for tenant onboarding, configuration, data export, and offboarding. A new tenant needs their data space provisioned, their configuration set up, their integrations connected, and their users created. When a tenant leaves, their data needs to be exported, retained for the legally required period, and then securely deleted. These lifecycle operations must be automated, auditable, and reliable.
- Automate tenant provisioning so it completes in under 5 minutes
- Build a tenant configuration system that supports per-tenant feature flags, branding, and settings
- Implement data export in standard formats for tenant portability
- Build tenant data deletion that is thorough (covers all data stores including backups) and auditable
- Test the full lifecycle quarterly — provision, configure, operate, export, delete — to catch drift