· 4 min read
Two databases, and nothing shared between them
I already had a system with clients, projects, tasks, auth and billing in it. Building the new product inside it would have saved me weeks, and I built all of it again instead, because of who was going to be logging in.
The reuse was right there
I run my business out of a system I built for myself. It has every client in it, every project, every payment, every invoice and every signed agreement, along with the tasks and notes I capture during the day.
This month I launched a product that's a shared pad of priorities and notes for a studio and each of their clients. Both sides see the same list, in their own branding, and the client ticks things off alongside you.
Look at those two paragraphs and the overlap is obvious. Clients, projects, a list of tasks, notes attached to them, authentication, a brand system for documents, billing. I had working versions of all of it, tested, in daily use. Adding a second kind of login to what I already had would have saved me several weeks, and for a while that was clearly the sensible plan.
I built the whole lot again in a separate codebase with a separate database, and the two share no tables at all.
The question that decided it
It wasn't about the features. The two products do want most of the same tables.
It came down to who's allowed to look. My own system has one rule, and the rule is that everything in it belongs to me. Every record is fenced to my account by the database rather than by the app being careful, and that fence is tested by a second real account trying to get through it and failing. One subject, one answer, and a test that proves it.
The moment a client can sign in to that system, the rule stops being "everything here is mine" and becomes a set of policies that each have to be right about which rows this particular person can see. That's an ordinary thing to build and I've built it. But getting one of those policies wrong in the system that holds every invoice I've ever issued is not the same size of mistake as getting one wrong somewhere else.
So I'd rather the answer to "can this client reach my financial records" be that there's no row to reach and no connection to reach it over. That's a stronger answer than any policy I could write, and it stays true on a day when I'm tired and shipping something quickly.
What I actually built instead
In the new product the isolation is in the schema rather than in the queries. Every policy goes through one membership check, and every child table keys on the workspace plus its own id instead of just the id. Pointing at something in another workspace isn't a rule somebody has to remember to apply, it's a foreign key that doesn't exist.
That design is only possible because the whole database was built around a tenant from the first migration. Bolting the same thing onto a schema that was written for one person would have meant adding a workspace column to every table and then being right about it everywhere, forever, including in all the code that was written before any of it existed.
The thing I'd been treating as reuse was mostly the parts that are easy to write. What I'd have been inheriting is a set of assumptions that were correct for a single-user system and silently wrong for a multi-tenant one.
It isn't a wall
Separating them didn't mean pretending they don't know each other.
The product reports into my own system, in exactly the same shape my other product does, as a stats feed over a token. Numbers go one way. There's no shared database, no shared user table, and nothing in my business system that the product can read.
That's the part I'd defend hardest if somebody told me I'd over-engineered this. A one-way feed of counts over a token took an afternoon. A shared database would have taken less than that, and then every feature either of them grew from that day on would have had to be right about the boundary.
What it cost, honestly
Weeks. Authentication, billing, a team model, brand handling, invitations, a whole second deployment to keep an eye on. All of it exists twice now, in two slightly different forms, because the two products need slightly different things from each.
There's a running cost too. A fix in one doesn't fix the other, and I've already had the experience of finding a bug in the product and recognising it from somewhere.
I'd still make the same call. The duplication is a tax I pay in hours, and it's a predictable one that shows up on days I've chosen. The other way round, the cost sits in a policy I wrote once and don't look at again.
The habit it left me with
Before I put a new feature inside something that already exists, I ask who's going to be allowed to look at it, and then I ask the same question about everything already in there.
If the two answers come out the same, sharing a database is ordinary reuse and I get on with it. When they come out different, what I'm really doing is widening who can reach everything that's already in there, and that's a much bigger decision than the one I thought I was making.