Every customer gets their own database
Ten days in July took Steward from a market-research document to a working CRM. 999 tests passing, nineteen roadmap epics done, and one architecture decision that shaped everything after it.
A database per customer
Every customer in Steward gets their own database. Not a shared table with a tenant column and a lot of hope — a real separate SQLite database, inside its own Durable Object, with its own migration history.
We still think that’s the right call. One customer’s data can’t leak into another’s through a forgotten WHERE clause, because it isn’t in the same database to leak from. Exporting a customer means reading one database. Deleting one means deleting one database, which matters the first time somebody asks you to prove you actually did.
The trade-off shows up in recovery, and we found it by bricking a test tenant so thoroughly it wouldn’t start.
What we got wrong
Here it is. When a tenant’s database wakes up, it replays any migration it hasn’t run yet, based on a stored version number. Restoring a backup rewinds that number. Obviously — you’re going back to an older state.
So the next wake-up replays every migration in between. And SQLite’s ALTER TABLE ADD COLUMN has no “if not exists.” The columns were already there, because the restored data had the newer schema even though the version number said otherwise. It threw.
And because it throws in the constructor, the database doesn’t come up at all. Our restore reported success and left the workspace behind it dead. Had that been a real customer, they’d have been staring at a login that wouldn’t work, with no way to tell us anything more useful than “it’s broken.”
What we learned
Three things, and the first one stung.
The whole point of a database per customer is that one customer’s problem can’t touch anybody else’s, and it delivered on that perfectly. Exactly one tenant was affected. It was just the tenant we were in the middle of helping.
Second, we nearly fixed it with a blanket try/catch around the migration runner, and we’re glad we didn’t. A migration system that swallows errors is worse than one that occasionally refuses to start, because at least the second one tells you something. What shipped catches that one specific error, bumps the version in a fresh statement, and lets every other error blow up exactly as before. The transaction has already rolled back by then, so the schema is fine. Only the bookkeeping was wrong.
Third, and this is the one we keep paying for: We hit check-then-act three separate times in one month. Restore’s audit logging. An escalation flow. This. Two requests turn up together, both check whether something exists, both get the same answer, both act on it. Every time, the fix was to move the check inside the transaction so the answer can’t go stale between reading it and using it.
Three times in four weeks. We’d like to spot that shape faster.
The rest of it
Accounts, health scoring, tasks, cases with incident linkage, renewals, CSV import, segments with bulk playbook runs, survey tokens, usage ingest. Finance dashboards with the retention numbers a CFO actually asks for — gross and net revenue retention, quick ratio, churn bands. An onboarding checklist, a demo mode, magic-link sign-in.
Nineteen epics in ten days isn’t a pace we’d claim as sustainable. It’s what happens when the architecture lands early and correctly: the first week is slow and the rest is downhill.
Three performance fixes are worth naming because they were all the same mistake. A health-trend query doing a self-join per data point. A coverage calculation running proportional to accounts times scorecards. An owner breakdown making two queries per owner. None of them were slow in development, because in development we had four accounts.
What we haven’t built
Google and Microsoft sign-in is a stub. Billing is on hold. Capturing revenue at deal-won is waiting on a product decision we haven’t made, not code we haven’t written.
And one correction to our own roadmap mid-month: We’d documented the finance dashboards as pointing at our payment provider rather than the customer’s. That’s backwards. Steward reports on your revenue, not ours, and connects to your Stripe or QuickBooks or Xero. Caught it in a doc review before it became code, which is the cheapest place to catch anything.
— Bruno