← Teardowns

How Is Supabase Built? Cloning the Open-Source Firebase Alternative

A technical teardown of Supabase's architecture — what it's actually made of, what you could clone in a weekend, and what would take you years.

Supabase isn't one product — it's twelve open-source projects wearing a trenchcoat

The pitch is 'Firebase alternative,' but Firebase is a single Google-owned monolith with a proprietary datastore. Supabase is the opposite bet: take Postgres, which has been battle-tested for 30 years, and wrap it with a constellation of open-source services that each do one job. That's PostgREST for auto-generated REST APIs, GoTrue for auth, Realtime for websocket subscriptions to database changes, Storage for S3-compatible file handling, pg_graphql for GraphQL, and Kong as the API gateway sitting in front of all of it. Supabase the company mostly writes glue, dashboards, and DX — the hard distributed-systems work was largely done by other people, some of it years before Supabase existed.

This matters for anyone thinking about cloning it. You're not reverse-engineering a secret sauce. Every one of those components is MIT or Apache licensed and sitting on GitHub right now. You can `docker-compose up` a large chunk of Supabase's actual stack today. The moat, if there is one, isn't in the code — it's in how well the pieces are stitched together and who trusts the result in production.

The core trick: Postgres row-level security as your entire auth layer

The cleverest architectural decision in Supabase is refusing to build a custom permissions system. Instead it leans entirely on Postgres's built-in Row Level Security (RLS). When a client hits the auto-generated REST or GraphQL API, PostgREST reads the JWT, sets the Postgres role and claims for that request, and lets the database itself decide what rows are visible. Auth isn't a layer bolted on top of the data — it's a property of the data.

This is elegant and also the part most cloning attempts get wrong. Engineers build a Firebase-alternative demo, wire up JWTs, and then reimplement permission checks in application code because RLS policies feel unfamiliar. That reintroduces exactly the kind of app-server-as-bottleneck architecture Supabase was designed to avoid. If you're cloning Supabase, the correct scope question isn't 'can I make a REST API over Postgres' — anyone can with PostgREST in an afternoon — it's 'can I make RLS policies debuggable, testable, and safe enough that non-security-experts don't shoot themselves in the foot,' which is a much longer project.

Realtime: the part that actually required hard engineering

Everything above is essentially config on top of existing tools. Realtime is where genuine engineering effort went in. It listens to Postgres's logical replication stream (WAL), decodes the changes, and fans them out over Phoenix Channels (it's written in Elixir, forked from a project called Realtime originally built for a different purpose) to potentially hundreds of thousands of connected clients, each with its own row-level-security-aware filter on what changes it's allowed to see.

That last part — per-connection RLS-filtered realtime delivery at scale — is genuinely hard distributed systems work: WAL decoding has to keep up with write throughput, connection state has to be tracked and garbage collected, and you need backpressure handling so one slow client doesn't stall the pipeline. A weekend clone can subscribe a websocket to `pg_notify` and call it 'realtime.' Doing it at Supabase's scale, with security filters applied per-subscriber without falling over under load, is where a naive clone quietly turns into a six-month project.

What an AI coding tool can actually reproduce today

If you prompted an AI tool to 'build me a Supabase,' here's what falls out fast: a Postgres instance, PostgREST or a hand-rolled equivalent for CRUD APIs, GoTrue or a JWT-based auth service, an S3-compatible storage bucket with signed URLs, and a dashboard UI for table editing and SQL queries. All commodity work. A competent AI coding agent can scaffold 70% of the visible surface area — the parts you'd screenshot for a demo — in a day or two, because the hard problems were already solved and open-sourced by the ecosystem Supabase built on.

  • REST/GraphQL API generation from schema — solved problem, PostgREST/pg_graphql do it
  • JWT auth with social logins — commodity, dozens of libraries do this
  • File storage with signed URLs — thin wrapper over S3-compatible storage
  • SQL editor / table editor UI — CRUD admin panel, well-trodden ground
  • Migrations and schema diffing UI — more fiddly but not novel

What doesn't clone: the operational moat

Here's where the 'is this cloneable' question gets its real answer. Supabase's product is a hosted, managed version of this stack running millions of Postgres instances for other people's production data. That means: automated backups and point-in-time recovery across every customer database, connection pooling (they run PgBouncer/Supavisor fleets) so serverless functions don't exhaust Postgres connections, read replicas, branching for preview environments, extension management (pgvector, pg_cron, postgis) kept compatible across upgrades, and 24/7 on-call for when someone's WAL replication falls behind and their realtime subscriptions start silently dropping events.

None of that shows up in a demo. It shows up at 3am when a customer's database runs out of disk during a migration and the difference between 'toy project' and 'business people trust with production data' becomes very expensive to fake. This is the classic oneprompt split: high technical cloneability (open-source stack, generous licenses, good docs, an AI agent can scaffold the UI and API surface fast) paired with a genuine operational moat (running thousands of Postgres instances reliably is unglamorous, expensive, and only gets easier with scale and experience you can't prompt your way into).

The real business moat: trust, ecosystem, and being the default

Supabase's defensibility isn't a patent or a proprietary algorithm — it's that it became the default answer to 'what backend do I use for my side project that might become a real company.' That default status compounds: more integrations get built assuming Supabase (Vercel, Next.js templates, LangChain, every AI-app tutorial on YouTube), more Postgres extensions get validated against their platform, more enterprises get comfortable pointing auditors at their SOC2 report. A clone starting today has to win that trust from zero, against a company that's already answered the compliance and reliability questions for thousands of paying customers.

There's also a subtler moat: Supabase employs or closely works with maintainers of some of the underlying open-source projects (PostgREST's creator works there, for instance). That's not a code moat — you can still fork the repo — but it's a talent and roadmap-influence moat that's slower to replicate than the software itself.

So — should you clone it?

If your goal is a side project or an internal tool, don't clone Supabase — self-host it. It's literally designed for that; `supabase start` gives you the whole stack locally via Docker. Cloning makes sense only if you're targeting a specific gap: a vertical (Supabase-for-healthcare with baked-in HIPAA config), a different cost model (serverless-billed Postgres instead of always-on), or a region/compliance niche the big platforms underserve.

If you do build a competitor, spend zero time reinventing PostgREST-equivalents — that's solved, and an AI coding tool will happily scaffold it for you in an afternoon. Spend all your time on the boring, expensive stuff: backup reliability, connection pooling at scale, and the on-call muscle that turns 'runs a demo' into 'something a company will put its production database on.' That's the actual moat, and it's the one no amount of prompting shortcuts.

Want the same teardown for any site?

Analyze a site →