COMPARISON · SUPABASE
Supabase RLS vs. SpiceDB: When Row Level Security Isn’t Enough
Supabase Row Level Security is one of the best ways to start securing an app: rules in SQL, enforced inside Postgres on every request. As products add teams inside teams, folders inside folders, sharing and AI features, those rules get harder to write, keep fast and reuse. That is where SpiceDB takes over.
Last reviewed November 2026. Try the interactive demo.
Short answer
For owner-only and simple team rules, Supabase RLS on its own is the right choice. Once access depends on relationships, such as nested teams, inherited folders, shares that expire, or the same rules in a search index, another service or an AI agent, SpiceDB is the stronger way to decide access. You can keep RLS as the enforcement layer: SpiceDB decides, a sync keeps an access table in Postgres current, and one short policy reads it.
What Supabase RLS does well
Supabase builds on Postgres Row Level Security. Each policy is attached to a table and runs every time the table is accessed, written in SQL, and combined with Supabase Auth for security from the browser to the database. It deserves its reputation:
- Defense in depth. Because RLS is a Postgres feature, it also protects your data when it is reached through third-party tools.
- Simple rules are genuinely simple. “Users can read their own rows” is a one-line policy using
auth.uid(). - Always consistent. The policy sees the data in the same transaction, so a change is visible to the next query immediately.
- Everything in one place. The Data API, Realtime and pgvector similarity search in the same database are all covered, with no extra service to run.
- Testable. Supabase recommends a test file per table that asserts allow and deny for every operation, run with
supabase test db.
Where RLS starts to strain
Real products rarely stop at “owners see their rows”. The demo walks one document app through seven requirements. The first two are easy for both approaches. Then:
- Teams inside teams. A policy can’t follow nesting on its own, so you add a recursive query in a security definer function, and every policy that mentions teams has to call it.
- Folders inside folders. Inherited access means walking each row’s folder ancestry. Supabase’s performance guide explains that Postgres evaluates a policy against each candidate row, so the cost scales with the rows a query scans, and it advises avoiding joins to the source table inside policies.
- Sharing with expiry. A shares table, optional user and team columns, an expiry check in every policy or a cleanup job, and another policy branch.
- Long access lists. Supabase’s own guidance notes that when a list-based policy passes about 1,000 items, a different approach may be needed.
- Hidden bypasses. Views bypass RLS by default unless created carefully, and the service role key bypasses RLS entirely, so every server-side path needs its own discipline.
- Rules that live only in Postgres. A search index, an external vector database, another team’s service or an AI agent’s tools can’t run your policies. Supabase Storage needs its own policies on
storage.objectsas well. - “Who can see this, and why?” A policy answers one request at a time. A share dialog or an audit needs a second query that mirrors every branch of the policy, kept in step by hand.
What SpiceDB does better
SpiceDB is an open-source permissions database inspired by Google’s Zanzibar. It stores relationships, such as Lee is on Platform, Platform is part of Engineering or the API folder is inside Specs, and computes access from them.
- Nesting is one word.
relation member: user | team#memberlets teams contain teams at any depth. - Inheritance is one arrow.
parent->viewlets access flow down folders, projects or organizations, however deep. - Expiring access is built in. Write a share with an expiration and SpiceDB stops using it on time.
- Both directions. LookupResources lists what a person can see; LookupSubjects lists who can see a document; checks can explain the path.
- One set of rules everywhere. Postgres, Storage, search, other services and AI agents all ask the same question.
- Built for graph-shaped work. SpiceDB caches each step of the graph across requests and was tested at one million checks per second on one hundred billion relationships. Read how.
- Tested like code. The schema and expected answers run in CI with
zed validate.
Side by side
| Supabase RLS alone | SpiceDB | |
|---|---|---|
| Owner-only rules | One line of SQL | Two lines of schema plus an API call |
| Nested teams | Recursive security definer function | One relation |
| Inherited folders | Recursive walk per candidate row | One arrow |
| Shares that expire | Shares table, expiry checks, cleanup | Built in |
| Who can see this, and why | A second, mirrored query | LookupSubjects and explain |
| Search, other services, AI agents | Rebuild the logic in each | Same API everywhere |
| Consistency | Same transaction, always current | Per-request choice with ZedTokens |
| Extra infrastructure | None | SpiceDB, self-hosted or managed |
The verdict. SpiceDB is the better tool for deciding access once your rules are about relationships, and the only one of the two that serves systems outside Postgres. RLS remains the better tool for enforcing simple rules inside Postgres with no extra moving parts. Most growing products end up using both.
Using them together
- Write relationships to SpiceDB when people share documents, join teams or move folders, from your app or an Edge Function.
- Keep an access table in Postgres current with a sync driven by SpiceDB’s change stream.
- Read it with one short RLS policy, so the Data API, Realtime and pgvector stay protected inside the database.
- Call SpiceDB directly for writes, share dialogs, search filtering and AI retrieval.
create function private.my_document_ids()
returns setof uuid language sql stable
security definer set search_path = '' as $$
select document_id from private.document_access
where user_id = (select auth.uid());
$$;
create policy "Documents: read via SpiceDB" on documents
for select to authenticated
using ( id in (select private.my_document_ids()) );
For people who can see very many documents, filter with SpiceDB’s lookup results in the query or an Edge Function instead of a long access list, in line with Supabase’s performance guidance.
Frequently asked questions
Should I replace Supabase RLS with SpiceDB?
Not necessarily. Keep RLS for simple rules and as the enforcement layer inside Postgres. Add SpiceDB when access depends on relationships such as nested teams, inherited folders or sharing, or when systems outside Postgres need the same rules.
Is SpiceDB slower than RLS because it is a separate service?
For simple ownership checks, RLS has no network hop and is hard to beat. For relationship-heavy rules, SpiceDB caches graph traversals across requests and can precompute permissions, while recursive RLS policies run per candidate row on every query. Test both with your data.
Does SpiceDB work with Supabase Auth?
Yes. Use the Supabase Auth user ID, the value of auth.uid(), as the subject in SpiceDB checks, so both systems refer to the same person.
Does RLS protect pgvector searches for RAG?
Yes, when the vectors live in Postgres tables covered by your policies. An external vector database is not covered by RLS; SpiceDB’s LookupResources can filter it.
See both approaches side by side
The interactive demo builds one document app both ways through seven requirements, then lets you sign in as five people, nest teams, share folders and expire a contractor’s access.
Open the demo · Try the quickstart · Get a custom demo
SpiceDB Field Resources is maintained by AuthZed, the company that created SpiceDB. AuthZed and Supabase are independent companies; Supabase is a trademark of Supabase, Inc. Supabase details reflect its published documentation as of November 2026; corrections are welcome at info@tryspicedb.com.