TL;DR: One enterprise client needed its own database: 45 outlets, about 20,000 users and 80,000 meals a day across 8 meal windows, all served by biometric terminals. A sizing worksheet from row sizes and call counts put it at about 115 MB of growth a day (3.5 GB a month) and about 43 GB of egress a month, so Supabase’s free tier (500 MB of database, 5 GB of egress) was out within days. The real question was self-hosting versus paying for managed. A grep showed the API made about 1,500 table calls through the Supabase client and 147 RPC calls, with no direct Postgres client anywhere, so leaving Supabase meant rewriting the data layer. And our own ops record (migrations nobody applied, schema changed by hand, deployed code that didn’t match git) said we would miss exactly the steps self-hosting hands you. We went managed: a dedicated project for the client. Count your missed steps before you count the bill.
Key takeaways
- Size a database from rows per day times bytes per row, per table, before you pick a plan. Rough numbers are enough to rule out the wrong options.
- Estimate egress from calls per unit of work, not from page views. One served meal was about a dozen database calls.
- Measure lock-in with a grep. The ratio of client-library table calls to RPC calls tells you how much of the app has to be rewritten to leave.
- Self-hosting doesn’t remove operational work. It moves backups, upgrades and recovery onto a team whose track record you already have.
- If nothing records which migrations ran, you can’t tell what state a database is in without checking its catalog object by object.
The brief: one client, its own database
The platform runs meal serving for corporate sites: canteens, mess halls, kitchens that feed shift workers. Most clients share one backend and one database. This client was large enough to get its own: 45 outlets, around 20,000 users, about 80,000 meals a day spread over 8 meal windows. Every meal is served at a biometric terminal (the device side is in the offline-queue post).
The shared database had already shown what happens when load outgrows it. On a normal day in the week before an outage in August, the shared backend handled about 97,500 HTTP requests; the timeouts post is the story of that outage. One client at 80,000 meals a day would be a multiple of that on its own. Keeping it off the shared box was not in question. Where its database should live was.
The sizing worksheet
Start with arithmetic. For each table that grows with meals, estimate rows per day and bytes per row (heap plus indexes, read off the schema’s column types and index count), and multiply:
| Table (generic) | Rows per day | Bytes per row, heap + indexes | Growth per day |
|---|---|---|---|
| Scan log (every terminal delivery) | 80,000 | ~900 | ~72 MB |
| Served meals | 80,000 | ~360 | ~29 MB |
| Meal reservations (two meals a day) | ~30,000 | ~420 | ~13 MB |
| Total | ~115 MB/day |
That is about 3.5 GB a month and around 40 GB a year, before table bloat and write-ahead log. The byte figures are estimates from the schema, not measurements, and I’d rather say so than dress them up. They don’t need to be exact. They need to be within a factor of two, and they are good enough to rule things out.
Egress came from the same approach, starting from calls instead of rows. Serving one meal took about a dozen database statements across the two endpoints a scan passes through. At 80,000 meals that’s close to a million calls a day. At an assumed 1.5 KB per response, it comes to:
~12 calls/meal × 80,000 meals/day ≈ 0.96 M calls/day
0.96 M × ~1.5 KB × 30 days ≈ 43 GB/month of egress
Supabase free tier: 500 MB database, 5 GB egress
▼ the database fills in about 4 days; egress runs out in the first week
The free-tier numbers are from Supabase’s pricing page as I write this (500 MB database size per project, 5 GB egress). One caveat on the comparison with the shared backend: 97,500 is HTTP requests and a million is database calls, and every request makes several calls. They aren’t the same unit. The order of magnitude is still the point: one client’s serving traffic, on its own, would put more load on a database than the whole shared backend did on a normal day.
Measuring lock-in with a grep
Self-hosting was the cost-saving answer on paper. Before arguing about it, I wanted to know what leaving managed Supabase would actually involve, and the codebase can tell you that in two commands:
# Illustrative. Count how the app talks to the database.
grep -rho '\.from(' routes services | wc -l # table calls through the client library
grep -rho '\.rpc(' routes services | wc -l # calls to database functions
grep -rlE "require\('pg'\)|from 'pg'|knex|prisma" routes services # any direct client?
The answers were about 1,500 .from() calls (a few of those are storage bucket calls, which
match the same pattern), 147 .rpc() calls, and no direct Postgres client at all. Every
query in the app goes through the Supabase client library and PostgREST.
That number matters for one of the three options more than the others. Self-hosting Supabase keeps PostgREST, so the code doesn’t change. Moving to plain managed Postgres on a cloud provider, without Supabase, means replacing every one of those 1,500 calls with SQL or a query builder. That isn’t a migration. That’s a rewrite of the data layer, for a saving that would never cover it.
| Option | What changes in the code | What we’d own | What it costs |
|---|---|---|---|
| Managed Supabase, dedicated project | Nothing; new keys and URL | Schema and migrations | A monthly bill that grows with disk and egress |
| Self-hosted Supabase on our own VM | Nothing | Backups, recovery, upgrades, monitoring, security hardening, uptime | Lower bill; every operational step is ours |
| Plain managed Postgres, no Supabase | Every one of ~1,500 table calls | Schema, plus a new data layer | Weeks of rewriting and retesting a serving path that works |
Why self-hosting lost: our own record
The self-hosting docs are honest about what you take on. Supabase’s self-hosting guide lists it: server provisioning, security hardening, Postgres maintenance, backups and disaster recovery, monitoring and uptime. It also notes that managed backups and point-in-time recovery aren’t available when you self-host.
None of that is hard to do once. The question is whether your team does it every time, and I didn’t have to guess. The production system we already ran had:
- migrations in the repo that had never been applied to production;
- crons that existed in code but were commented out, so nobody could say what was supposed to run;
- schema changes made by hand in production, with no migration behind them;
- deployed code on the server that didn’t match what was in git.
Later digging added two more: cron code running on the server that wasn’t in git at all, and per-role timeouts set in production by someone, at some point, with no migration recording it.
None of these is a disaster on its own. Together they are a record, and a team with that record running its own Postgres is a team that will one day find out the backups stopped in March. Managed Supabase does the steps we’d skip. The bill is the price of not needing discipline we hadn’t shown. So the client got a dedicated managed project and its own app server, and the shared backend stopped carrying its load.
Building a database you can’t replay
Deciding was the easy part. Building the client’s database showed how far that record went.
By late September the client’s database already existed, and it wasn’t in a state anyone could name. A script parsed every migration file for the objects it creates (tables, columns, functions, indexes, constraints, triggers) and checked each one against the database’s catalog: 1,184 objects across 155 files. On the client’s database, 22 migrations’ worth of objects were half-applied, out of order, and 64 objects were missing. Nothing recorded which migrations had run. No filename order predicts a state like that, so replaying the files would have been guesswork.
The schema file in the repo couldn’t stand in for production either. Production had 129 tables and 205 functions. The repo’s copy, about five weeks old, had 122 tables and around 190 functions.
So the client’s database was rebuilt from a fresh dump of production’s schema, while it was still empty enough for a rebuild to be cheap. That is an honest measure of where the source of truth had been living.
Setup scripts that wrote to the wrong database
The second finding was smaller and more instructive. In mid-September, a set of setup scripts loaded the client’s meal timings, menu sub-options and a three-language menu. They read the database URL from the environment, and the environment at the time pointed at production. At that point the client’s own database didn’t exist yet, so production was the only database in play, and that was a known, deliberate choice.
The problem showed up when the rebuild ran, one to three weeks later. The rebuild’s first check of its target found the client’s new database with almost no reference data and no users at all. Everything those scripts had set up was in production, under one outlet, and the client’s database had never seen any of it. Nothing was damaged (every script had written a rollback snapshot), but every one of them had to be re-run against the right target.
The lesson isn’t “scripts shouldn’t touch production”. It’s that a script whose target is
whatever the environment happens to say has an implicit target, and implicit targets move.
A repo whose .env switches between two projects will, eventually, run the right script
against the wrong one.
Guards that refuse instead of warn
The rebuild script was written to refuse rather than trust. Before it touches anything:
# Illustrative.
refuse_unsafe_target() {
local url="$1"
[[ -z "$(host_of "$url")" ]] && die "no host in target URL"
[[ "$url" == *"$PROD_REF"* ]] && die "target is production; refusing"
[[ "$url" == *":$POOLER_PORT/"* ]] && die "transaction pooler; use a direct session connection"
if has_non_reference_rows "$url" && [[ "$FORCE" != 1 ]]; then
die "target already holds real data; pass --force if you mean it"
fi
}
refuse_unsafe_target "$TARGET_URL"
dump_schema "$SOURCE_URL" > schema.sql && sanity_check schema.sql # enough tables, enough functions
dump_full "$TARGET_URL" > "safety-$(date +%s).sql" # before anything is dropped
The pooler check is there because DDL and long restores don’t belong on a transaction pooler, which can hand consecutive statements to different backend sessions. The sanity check on the dump catches the quiet failure where a dump “succeeds” with half the schema. The safety dump comes before anything is dropped, every time, including on a target that is supposed to be empty.
The app got the same treatment. In the client’s deployment, it refuses to start if the database URL points at the shared production project, or if the key it was given belongs to a different project than the URL. The deploy script reads the boot log and stops the process if it names production. A process that won’t start is a five-minute problem. A process that starts and writes a client’s data into another client’s database is not.
DROP SCHEMA takes the grants with it
One trap from the rebuild is worth knowing if you ever reset a Supabase schema. The clean
way to start over is DROP SCHEMA public CASCADE; CREATE SCHEMA public;. The new schema
comes back with default privileges, not the ones the old one had. Supabase’s API roles lose
USAGE on it, and without USAGE they can’t see anything in it, so PostgREST answers 404
for every table. The Postgres docs on schema privileges
cover why: a role needs USAGE on a schema to access any object inside it.
-- Illustrative.
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
GRANT USAGE ON SCHEMA public TO anon, authenticated, service_role;
-- then restore the schema dump
The rebuild script captures the schema’s original grants before dropping it and replays them afterwards, rather than trusting a hand-written list.
What actually broke in setup
Nothing broke for users, and I want to be clear that this was setup, not an incident. What broke was the assumption that the repo described the system. The client’s database had drifted from the migrations with no record of how. The schema file was five weeks behind. A set of scripts had put a client’s configuration in the wrong database for weeks without anyone noticing, because the only check that would have noticed (looking at the target) didn’t exist until the rebuild added one.
The client is live on its dedicated project, running as a pilot that had grown to 26 active outlets by late November. I don’t have measured size or egress numbers for its database yet to set against the worksheet, so this post can’t tell you how close the estimate was.
FAQ
Should I self-host Supabase or use the managed service? Self-host if your team reliably does backups, restores, upgrades, monitoring and security patching, and the saving is worth that time. Otherwise pay for managed. The deciding evidence is your own record: unapplied migrations, hand-made schema changes or deployed code that doesn’t match git are the same steps self-hosting will hand you.
How do I estimate how fast my Postgres database will grow? For each table that grows with usage, multiply rows per day by bytes per row, counting indexes as well as the table itself. Bytes per row can be read off column types and index count. Add the tables up, multiply by 30 for a month, and leave headroom for bloat and write-ahead log. Within a factor of two is enough to choose a plan.
How do I estimate database egress? Count database calls per unit of work (one order, one served meal), multiply by daily volume, then by an average response size, then by 30. In our case about 12 calls per meal, 80,000 meals a day and an assumed 1.5 KB per response gave about 43 GB a month. Measure response size on a real day if you can; the assumption is the weakest input.
What are the Supabase free tier limits? At the time of writing, the free plan includes a 500 MB database per project and 5 GB of egress, and free projects pause after a week of inactivity. Paid plans include much more disk and egress and bill beyond that. Check the pricing page on the day you decide, since limits change.
How hard is it to move off Supabase to plain Postgres?
Count the calls. If the app reaches the database through the Supabase client (.from()
table calls and .rpc() function calls) and has no direct Postgres client, leaving means
rewriting every table call. Self-hosting Supabase keeps PostgREST and needs no code changes;
moving to plain Postgres does.
How do I stop a script from running against production by accident? Make the target explicit and have the script refuse the production project, by reference or host, before it connects. Refuse targets that already hold real data unless a force flag is passed. Take a backup of the target before any destructive step. For the app itself, refuse to boot if its configuration points at the wrong project.
Why does PostgREST return 404 after DROP SCHEMA?
Dropping and recreating a schema resets its privileges. The API roles lose USAGE on the
schema, so they can’t see any table in it, and PostgREST reports every table as not found.
Grant USAGE on the schema to the API roles again, or capture the old grants before the
drop and replay them.
What I’d still improve
- Shrink the scan log, which I proposed and haven’t shipped. It’s the biggest line in the worksheet: about 72 MB a day, a row for every delivery with the full response body. Keeping only rejections and errors, without the body, would take it to about 1 MB a day. The rejections are the part that matters, because when a client asks why the terminal counted more scans than the bill, the refusals are the whole difference. It’s still on the list.
- Measured numbers. The worksheet is an estimate. Now the client is live, its real disk and egress should go next to the estimate, and the worksheet should be corrected with whatever I got wrong.
- Migration tracking on the shared database. The rebuild records which migrations the client’s database has. When I wrote it, production had no such record, so it needs the same table.
- One command to rebuild from the repo. Building from a production dump was the right call on the day. The goal is a repo that can build the database by itself, and it isn’t there yet.
The one idea to take away
Self-hosting doesn’t remove work; it moves every missed step onto you, so count your missed steps first.
The bill is easy to compare: one number per option. The operational cost isn’t on any pricing page, and it shows up only in your own history. Unapplied migrations, schema changed by hand, code that doesn’t match git: those are the steps a managed service quietly does for you, and the steps you’d quietly skip when it’s yours.
I write about backend reliability, Postgres and operations from work on food-tech and healthcare platforms. More on what I build and how I work, on the outage that showed how much load a shared database can take, and on cutting cloud costs by fixing infrastructure. Before you price self-hosting, grep your repo for migrations that never ran.