The Zeroic Journal

Supabase multi tenant RLS: patterns that hold up

Shared schema, schema per tenant or a project per tenant: when each wins on Supabase, what fails first in each, and where the Stripe subscription belongs.

On this page 8 sections
  1. Use Supabase multi tenant RLS by default
  2. Where the tenant id comes from
  3. What breaks first in a shared schema
  4. Schema per tenant buys little on Supabase
  5. Database per tenant is a pricing decision
  6. Map billing to the tenant row
  7. How to choose your isolation model
  8. How ComplyAssist shipped role-based access in 8 weeks

Supabase multi tenant RLS - a shared schema, a tenant_id on every table and policies that check membership - is the right default for most B2B SaaS. Move a customer to its own Supabase project only when a contract demands a dedicated database: on the Pro plan each extra Micro project adds $10 a month, so isolation becomes a per-customer cost.

Most Supabase apps start with policies like auth.uid() = user_id. That model breaks the day your first business customer asks to invite a colleague, and the rewrite gets harder with every table you add. Supabase has also been changing the ground under existing projects: since October 30, 2026, new tables on existing projects need explicit grants before the Data API can reach them, and the legacy anon and service_role keys are due to be removed in late 2026. If you’re touching your access model anyway, this is the quarter to get tenancy right.

Use Supabase multi tenant RLS by default

The pattern has four parts: a tenants table, a memberships table that maps users to tenants with a role, a tenant_id column on every tenant-owned table, and one helper function that every policy calls.

create table private.memberships (
  tenant_id uuid references public.tenants(id),
  user_id uuid references auth.users(id),
  role text not null,
  primary key (tenant_id, user_id)
);
create index on private.memberships (user_id);

create function private.my_tenant_ids()
returns setof uuid language sql stable
security definer set search_path = '' as $$
  select tenant_id from private.memberships
  where user_id = (select auth.uid())
$$;
grant usage on schema private to authenticated;

create policy "members read projects"
on public.projects for select to authenticated
using (tenant_id = any (array(select private.my_tenant_ids())));

Every detail in that block is there for a reason documented in the Supabase RLS guide:

  • The helper is security definer with an empty search_path. It reads memberships without tripping that table’s own policies, and the pinned path stops a caller from swapping in their own objects.
  • It lives in a schema the API doesn’t expose. Supabase warns that a security definer function in an exposed schema is callable over the Data API with its creator’s privileges.
  • user_id has its own index. A composite primary key on (tenant_id, user_id) only indexes the leading column, so lookups by user still scan without the second index.
  • to authenticated is named. Anonymous requests stop before the policy body runs.

The array(select ...) wrapper matters most. In Supabase’s RLS performance benchmarks, a team-membership policy that called the function directly took over 2 minutes on a 1M-row table, with or without an index. Wrapped so Postgres evaluates it once per statement, and with tenant_id indexed, the same query ran in 2-3 milliseconds for users in 10 to 500 teams. Index tenant_id on every tenant-owned table, and filter by it in your queries too: in the same tests, adding an explicit filter to the query cut a read from 171 to 9 milliseconds.

Write policies need a with check that tests the same membership. Without it, a user can insert or move a row into a tenant they don’t belong to. For the per-symptom fixes when a policy hides or leaks rows, see our guide to Supabase row level security not working.

Where the tenant id comes from

You have two places to read tenancy from, and they fail differently.

A membership lookup, as above, is always current. Remove someone from a tenant and their next request sees nothing. The cost is a query per statement, which the wrapper keeps small.

A JWT claim is free to read with auth.jwt(). Supabase’s custom access token hook runs before each token is issued and can add a tenant or role claim. Two caveats decide whether it’s safe:

  • Store it in app_metadata. The RLS guide is explicit that users can update their own user_metadata through supabase.auth.update(), so a tenant id there is one API call from being forged.
  • Accept that it goes stale. A membership change doesn’t show in auth.jwt() until the user’s token refreshes. For a removed employee, that window is access you meant to revoke.

Our rule: authorize from the membership table, and use a JWT claim only for which tenant the user is looking at right now, the “active workspace” in the UI. Keep the claim small, since Supabase notes some browsers cap each cookie at 4,096 bytes.

What breaks first in a shared schema

The policy pattern holds. The leaks come from paths that skip it.

Server code with a secret key. Secret keys and the legacy service_role key run as a role with BYPASSRLS. Every webhook, cron job and admin route that uses one sees every tenant, so each of those queries needs its own where tenant_id = .... When we review a B2B Supabase app, this is the first list we write down.

An ORM connected as the table owner. The PostgreSQL row security docs state that table owners normally bypass row security unless the table is set to FORCE ROW LEVEL SECURITY. If Prisma or Drizzle connects as postgres, your policies don’t apply to it at all.

Global unique constraints. The same docs warn that unique, primary key and foreign key checks always bypass row security, and can leak information through “covert channels.” A global unique (slug) tells a user in tenant A that tenant B already took acme. Scope uniqueness to the tenant: unique (tenant_id, slug).

Tables created by migrations. A table created through SQL or an ORM has RLS only if the migration turns it on, and since October 30 it also needs grants. Supabase’s 2025 security retro recommends an event trigger that enables RLS automatically, so a new table can’t ship open.

Schema per tenant buys little on Supabase

Schema per tenant puts each customer’s tables in their own Postgres schema. A query that forgets its filter can’t cross into another tenant, and dropping one customer’s data is a single drop schema.

On Supabase, the costs arrive fast. Every schema has to be added to the exposed schemas list in the API settings and granted to anon, authenticated and service_role, per the custom schemas guide. Your client has to pick the schema per request. Every migration runs once per tenant, and a failure halfway leaves customers on different versions. You still need auth, and auth.users is shared across all of them, so the membership table and policies don’t go away either.

It wins in one case: a handful of large customers who each need custom tables or columns of their own. For a self-serve product with hundreds of small accounts, it’s the same isolation work as RLS with more moving parts.

Database per tenant is a pricing decision

On Supabase, a database per tenant means a project per tenant. Isolation is total: separate Postgres, separate auth, separate backups, and no noisy neighbor.

The Supabase pricing page puts numbers on it. The Pro plan is $25 a month and includes $10 of compute credits, enough for one Micro instance. Each additional Micro project adds $10 a month. Forty tenants on Micro comes to $25 + (40 x $10) - $10 = $415 a month before any usage, and a tenant that needs a Medium instance costs $60 on its own. Then add the work: migrations deployed to 40 projects, 40 sets of keys to rotate, and users who belong to two customers needing two accounts.

That’s why it belongs in your price list as a premium tier. Offer a dedicated tier for the enterprise customer whose security review demands it, priced above what the project costs you, and keep everyone else on the shared schema. The same reviews usually ask for single sign-on next; enterprise SSO integration hangs off the same organization model.

Map billing to the tenant row

Billing follows the same boundary as data. Create one Stripe customer per tenant and store its id on the tenants row. For per-seat pricing, set the subscription quantity to the tenant’s member count; Stripe’s subscription quantities docs describe this as per-seat licensing and prorate the change when the quantity moves.

In the database:

  • subscriptions is keyed by tenant_id, with a SELECT policy for members so the app can show the plan.
  • No INSERT or UPDATE policy for users. Only your Stripe webhook handler writes billing state, server side, which is one of the few places a secret key belongs.
  • Plan limits live in the database. The security definer function that adds a member checks the seat count against the plan before it inserts, so a client can’t invite past the limit.

Our Stripe subscriptions on Supabase guide covers the webhook sync and dunning side in detail.

How to choose your isolation model

IfUseWatch for
Self-serve B2B, any number of tenantsShared schema + RLSSecret-key code paths, table-owner connections, global uniques
A few large customers with custom tablesSchema per tenantPer-tenant migrations, exposed schema list, grants
A contract requires a dedicated databaseProject per tenant$10+ a month per tenant, migrations and keys times N
A mix of all threeRLS for most, a dedicated tier for a fewKeep tenant_id on every table so moving a tenant out is a data copy

Whatever you pick, add tenant_id to every tenant-owned table from day one, even in a single-tenant app. Retrofitting it is the slowest part of every later change. If you’re hiring for this work, our Supabase developers set it up this way by default, and the senior developers by stack page covers the rest of a typical SaaS stack.

How ComplyAssist shipped role-based access in 8 weeks

We built ComplyAssist, a compliance management SaaS, in 8 weeks. It combines a compliance library, task assignment and deadline reminders, with role-based permissions for two kinds of user: a company’s in-house team and the external consultants it brings in. The external consultant is the user that breaks single-tenant permissions - one person, several client companies - and it’s the reason the membership-with-role model above exists.

Billing follows the organization too. ComplyAssist shipped with plans running from a 2-user Lite tier at $1.99 a month up to Enterprise, so seat limits and plan state belong to the organization rather than an individual login. We also built KeepTrack, a white-label client portal used by hundreds of agencies and consulting firms, where each provider’s clients work in views branded as the provider’s own.

If you’re planning a B2B product, our MVP development service sets up the tenant model, policies and billing mapping before the first feature table, because every table after that depends on it.

Frequently asked questions

Should I use RLS or schema per tenant for a Supabase SaaS?
Use row level security on a shared schema unless you have a specific reason not to. On Supabase, every extra schema has to be added to the exposed schemas setting and granted to the API roles, and every migration runs once per tenant. Schema per tenant suits a small number of large customers who need their own tables.
How do I store the tenant id for Supabase RLS policies?
Keep membership in a table that maps users to tenants with a role, and have policies look up the tenant ids through a security definer function. If you also put a tenant claim in the JWT, store it in app_metadata, never user_metadata, because users can edit their own user_metadata. Remember that a JWT claim stays stale until the token refreshes.
Does the Supabase service role key respect tenant isolation?
No. Secret keys and the legacy service_role key run as a role with the BYPASSRLS attribute, so every tenant policy is skipped. Any server route, webhook or background job that uses one must filter by tenant id in its own code. Treat each of those code paths as a place where one customer could read another customer's data.
When does a SaaS need a separate database per tenant?
When a customer contract or regulator requires a dedicated database, or one tenant's load is large enough to slow everyone else down. On Supabase that means a project per tenant, and on the Pro plan each extra Micro project adds 10 dollars a month of compute, plus separate migrations, backups and auth for every one of them.
How should Stripe billing map to tenants in a multi-tenant SaaS?
Create one Stripe customer per tenant and store its id on the tenant row. For per-seat pricing, set the subscription quantity to the tenant's member count and let Stripe prorate the change. Members can read their tenant's plan through RLS, but only your webhook handler, running server side, should write billing state.

References

  1. Supabase - Row Level Security
  2. Supabase - RLS performance and best practices
  3. Supabase - Custom Claims and Role-based Access Control
  4. PostgreSQL - Row Security Policies
  5. Supabase - Using custom schemas
  6. Supabase - Breaking change: tables not exposed to the Data API automatically
  7. Supabase - Pricing
  8. Supabase - Security retro: 2025
  9. Stripe - Set product or subscription quantities

More from the journal

Hear from Prashant within 24 hours.

Prashant Abbi Partner @ Zeroic

Designing tenants for a B2B SaaS on Supabase? We set up the tenant model, the policies and the billing mapping before the first customer signs in, as part of a 5-6 week MVP Sprint with senior engineers.

See the MVP Sprint, or book a 30-minute call