Tenancy: one hosted service, namespaces in one database
Status: accepted, 2026-10-07. Supersedes the 2026-10-07 decision "one organization per deployment" (DEC-01M4AV7NQYJPF1V9GNW02TJ458).
Decision
refs is one hosted service at useref.dev, not software each team deploys. Every person has a username, which is their personal namespace, and people create organizations, like GitHub. Usernames and organization names share one space.
All namespaces live in one D1 database. Tenant data carries a namespace_id (repositories, labels, invitations, memberships), and everything else hangs off a repository. All Git data lives in one Artifacts namespace, and each repository's storage has an opaque name.
Why
- The product changed: refs is hosted for people who don't run their own Cloudflare account. That was the "revisit when" trigger of the old decision.
- Rows tagged by namespace was the cheapest path from the existing schema. A database per namespace would make every migration a fleet rollout and needs a registry that authorizes every request.
- The Artifacts Workers binding is fixed to one namespace, and it has no way to open another namespace at runtime. A namespace per tenant would mean moving every read in
browse.ts,diff.ts,gitwrite.tsanddecisions.tsto the REST API.
How isolation holds
- Every repository lookup goes through
findRepoRecordby<namespace>/<repo>, and its policy comes from the viewer's membership in that repository's namespace (namespacePolicy). A private repository is visible only to members of its namespace. - Lists are scoped: repositories, tasks, labels, members and invitations filter by namespace.
- Durable Objects are named by repository id or user id, which never collide across namespaces.
apps/backend/test/tenancy.test.tschecks the boundaries. Add a case there with every new list or lookup.
Options rejected
- One organization per deployment. It doesn't fit a hosted service with sign-up.
- A database per namespace behind a registry. It is strong isolation, but it needs fleet migrations and an authorization control plane. Revisit it when one database nears D1's limits.
- An Artifacts namespace per tenant. The binding can't switch namespaces at runtime (see Why).
Revisit when
- the largest table nears 10 GB or D1 write latency is dominated by queueing, or
- the Artifacts binding can open a namespace at runtime, which makes physical Git isolation per tenant a small change.