← Writing

Per-tenant RAG isolation in multi-tenant AI SaaS

Yunseop Im · Software engineer, AI engineering · M.S. CS, Georgia Tech

"Add RAG to your SaaS" is the easy part. The hard part nobody warns you about: in a multi-tenant product, retrieval is a security boundary. If tenant A's query can surface tenant B's documents, you don't have a search bug — you have a data breach with a latency SLA. This post is the design I use, in two phases, and the failure modes that decide which one you actually need.

The two architectures

Every managed vector/RAG service forces a choice. Both are legitimate; they fail in different places.

Phase 1 — siloed storesPhase 2 — shared store + metadata
LayoutOne store per tenant; user_id → store_name map in your datastoreOne shared store; every doc tagged customMetadata:{tenant_id}
Retrieval callAttach only that tenant's store per requestAlways pass metadata_filter set server-side
Isolation strengthPhysical — impossible to crossLogical — depends on your filter never being bypassed
Scaling ceilingProvider project quotas (per-store limits, total project cap)Index size, metadata-filter latency
GDPR deleteDrop the whole store — cleanDelete by metadata — eventual consistency
Best forUp to a few thousand tenants10k+ tenants, cost pressure

The rule that matters most

Tenant scope is enforced in the request builder, never trusted from the client.

In the shared-store design, the single most dangerous line of code in your system is a metadata_filter assembled from a client-supplied parameter. One missing parameter and every tenant's documents are retrievable. The filter must be constructed server-side from the authenticated session — the client can narrow within their own scope, never widen it.

Quota math is a design input, not an afterthought

Managed RAG billing has non-obvious multipliers that determine your unit economics before you write a line of product code. The facts I plan around (verify against your provider's current docs — these change):

Worked example: with a 40MB-per-user cap and a 1TB project quota, your ceiling is ~8,000 full-cap tenants — not the 100k your marketing page hopes for. Per-user limits (doc count, file size, total bytes) are therefore the cost control, and they should differ by plan tier while isolation stays identical for everyone.

Failure modes I've seen (and designed against)

  1. Unscoped attachment. A code path attaches "the knowledge store" without scoping to the requesting user. Cross-tenant leak. Fix: the request builder takes the authenticated user as a required argument — no default, no optional.
  2. Client-supplied filters. Frontend sends ?tenant_id=. Trivially exploitable. Fix: filter built from session, client params can only narrow.
  3. Stale index after delete. User deletes a document; the vector store still serves it for hours. Fix: treat retrieval freshness as part of the delete contract, not best-effort.
  4. Quota bypass via concurrency. Per-user limits checked at upload but not at query time. Fix: enforce at both boundaries.
  5. Store proliferation. Phase-1 silo design hits the provider's project-wide store cap at exactly the moment you're scaling. Fix: know your ceiling before you need Phase 2, and keep the retrieval interface identical across both so migration is a backend swap, not a rewrite.

The meta-lesson

Multi-tenant RAG is where "it works in the demo" goes to die. The demo has one user; production has adversarial neighbors. The design that survives is boring: scope enforced server-side, quotas as first-class limits, deletion as a contract, and a migration path between isolation architectures that doesn't change your API. Get those four right and the retrieval quality questions — chunking, reranking, hybrid search — are the fun part you actually get to spend time on.

Related: graphrag-lab — retrieval experiments · agent harness teardown · profile · LinkedIn