
Multi-Tenant SaaS Data Isolation: A Practical Design Review for Founders
Review tenant boundaries across requests, storage, background jobs, files, search, support access, and AI features before a SaaS launch.
MVPs & SaaS Projects
Review PostgreSQL row-level security with the real SaaS database role, trusted tenant context, pooled-connection tests, explicit write policies, and controlled bypass paths.

LET’S BUILD SOMETHING USEFUL
Talk to ATARAXY DEVELOPERS (SMC-PRIVATE) LIMITED about your website, app, or custom software.
A SaaS application can include tenant filters in every query its developers remember and still miss an export, background job, or newly added endpoint. PostgreSQL row-level security can provide another place to express row access rules. Its effectiveness, however, depends on the role executing the query and the trustworthiness of the context used by the policy. A successful test as a database administrator does not demonstrate the customer application’s actual boundary.
Consider a service where each customer organization owns projects and project documents. The application normally acts for one authorized organization at a time. The review should establish how that organization is selected, how the database receives the selection, and which operations are allowed on the resulting rows. The following approach treats database policies as part of an authorization design, with explicit tests for both expected access and expected denial.
List the tenant-owned tables and their relationships. Decide whether every row carries a tenant identifier directly or obtains its scope through a relationship. Identify shared reference data separately. A global list of document types has different access requirements from a customer’s uploaded document. Avoid forcing both into the same policy merely because they appear on one screen or are joined by a convenient query.
Write examples of allowed and denied operations for each table. An organization member may read its projects, create a document under an authorized project, and update selected fields. It should not move a document to another organization by changing a tenant field. Include membership changes, delegated administration, and service jobs in the model. These examples become the acceptance criteria for the policy and the application code that supplies its context.
PostgreSQL’s row-security documentation explains that enabling row security without an applicable policy gives default denial for normal row access. It also identifies bypass behavior for superusers, BYPASSRLS roles, and normally table owners. FORCE ROW LEVEL SECURITY can subject an owner to policies. Review these distinctions against the deployed role arrangement; a privileged development connection can hide an ineffective production design.
The documentation also distinguishes row visibility from checks on new or changed rows, and explains how permissive and restrictive policies combine. Review the combined result, not each policy in isolation. A broadly permissive rule can change what another restrictive-looking rule appears to accomplish. Keep the application role separate from schema ownership and migration privileges where practical, and inspect inherited privileges as part of the deployment review.
If a policy relies on application-provided tenant context, derive that context from the authenticated request and verified membership. A client-supplied organization identifier is a request to select a scope, not proof that the user belongs to it. Validate the selection before opening the database work for that tenant. Keep the authorization decision and the database context tied to the same request or job.
Be explicit about the threat model. A custom session setting is not an independent identity boundary if a caller can execute arbitrary SQL and change that setting through the same role. Continue to use parameterized queries and control database access. Row policies complement application authorization and query safety; they do not make an unrestricted database credential safe to distribute to customers or erase the consequences of compromised privileged code.
Connection pools make context lifetime important. A connection used for one customer can later serve another request. Establish the tenant context within a controlled transaction or another clearly bounded mechanism, and verify what happens on commit, rollback, timeout, and reuse. Use the exact pooling mode and driver behavior deployed by the application. A test with a fresh connection for every request can miss context leakage between borrowers.
Run a sequence that alternates two test tenants through the same small pool. Include a request that fails halfway through and another that omits context entirely. The missing-context case should fail closed or produce the deliberately defined denial behavior, never inherit a prior customer’s scope. Record which database role and tenant context were active for each test without logging credentials or unnecessary customer row contents.
Reading only the correct projects is not enough. Test inserts, updates, deletes, upserts, and bulk operations that the application actually uses. Try assigning a new document to a project owned by the other test tenant. Try changing the tenant identifier of an existing row. Check the error or affected-row behavior and ensure the application turns it into a useful response without revealing unauthorized record details.
Review relationship integrity separately. A tenant-scoped document row should not accidentally reference another tenant’s project through an identifier that the application failed to validate. Choose database constraints and application checks appropriate to the schema. The exact implementation depends on the data model, but the acceptance criterion is concrete: a permitted write must not create a relationship that crosses the intended customer boundary.
Inventory the code paths that run without a browser session. Background exports, scheduled jobs, search indexing, and support tools often use different credentials. Decide whether each should run within a single tenant scope or through an explicitly privileged operational path. Avoid giving a worker unrestricted access simply because setting context requires additional plumbing. Name the owner and purpose of every deliberate bypass.
For administrative recovery, require an auditable operation that states the target tenant and intended action. A general SQL console is a different capability from a customer support screen that reads one authorized record. Keep those capabilities separate. Test the customer-facing path using the customer application role, and test privileged maintenance procedures independently so their legitimate exceptions do not become accidental shortcuts in normal requests.
Create a compact authorization fixture with two tenants, shared reference rows, multiple membership states, and known expected results. Run it through the real application data access layer. Include denied cases in the release checks and inspect query plans for representative permitted workloads. A correct policy that adds an unexpectedly expensive lookup can still disrupt the service, so measure its effect using realistic data shapes.
AI can help draft a matrix of missing test cases or explain a policy expression for review. It should not be the authority that approves the tenant boundary. Require executable evidence for the deployed role, connection lifecycle, and write paths. Keep the fixture and policy version in the deployment record so later schema changes can be evaluated against the same explicit expectations.
PostgreSQL row security is most useful when its role assumptions and tenant context are visible and testable. Review bypass privileges, bind context to the right work, and exercise both reads and writes through reused connections. Include operational paths in the same inventory, with deliberate exceptions, so the database policy supports a clear SaaS authorization model rather than an unverified sense of isolation.
LET’S BUILD SOMETHING USEFUL
Talk to ATARAXY DEVELOPERS (SMC-PRIVATE) LIMITED about your website, app, or custom software.