GeezerVison is showing github.com — design(id): split tenant data between UserDO SQLite, per-user Turso and D1 (from #9080) · Issue #15482 · developing-today/code
design(id): split tenant data between UserDO SQLite, per-user Turso and D1 (from #9080) #15482Labels app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/mMedium: expected under 1 day of workkind/designA design proposal (design-architect): multi-step, phased, decision-bearingmeta/enrichedIntake review done: acceptance criteria, links, and normalized labels addedpriority/normalOrdinary priority (the default)status/needs-triageNot yet triaged; needs a first look DescriptionGap from the #9080 gap analysis (component B of #9078). Design only.
What is missing
#9083 decided that a tenant has both the per-user Durable Object SQLite built by #3811 (UserDO, renamed TenantDO in docs) and a per-user Turso database as its data store. No record says which data lives where. The landed hosted store is DO SQLite only; the #5681 decision (Turso default and world primary, D1 for large shards) is not reflected in code. #14866 separately proposes moving data planes to Workers + D1, which may cut across this.
Done when
- A dated design record decides, per data family (signed events and heads, KV, blob references, usage/metering, export state, world journals), whether it lives in DO SQLite, the per-user Turso DB or D1, and why.
- It states how the decision squares with design(id): serverless edition storage — D1 vs Turso vs both for
id on Cloudflare Workers #5681, design(pm-stack): tenancy architecture — per-user Turso databases + central tenancy DB, served by Workers and Durable Objects #9083 and program: move PM Stack, queues, and all unblocked services to Workers + D1 (Cloudflare-first) #14866, and which issue implements the move (E6 impl(pm-stack): E6 — tenant DB store adapter in id-store (#9083) #12801 for the Turso adapter).
Generated by Claude Code
Acceptance criteria
- The design states, per data class, whether it lives in UserDO SQLite, per-user Turso, or D1 — with the reason for each placement.
- Migration/consistency implications of the split are named, not left implicit.
- The design is recorded on this issue (or a linked doc) in enough detail for the sibling implementation slices to proceed without re-deciding placement.
Activitydeveloping-today-fleet commented on Nov 26, 2026 Intake review
🤖 Agent note · handed off
- Agent: fleet monitor (repo-fleet-monitor)
- Session / ID: repo-fleet-monitor run 2026-11-26 02:14 CST
- Found via: monitor reconciliation (intake enrichment, Duty 2)
- Task: Intake enrichment — acceptance criteria appended, labels normalized, meta/enriched applied.
- Expectation: Ready for triage/queue routing as labelled.
- Links: n/a
developing-today-fleet commented on Nov 26, 2026 Claimed by worker felix (agent felix, muse seat) — design pass: dated design record under doc/ deciding per-data-family placement across UserDO SQLite, per-user Turso and D1, squared with #5681, #9083 and #14866; implementation slices filed with dependency edges where a gap exists. PR will be left open for Felix's merge.
developing-today-fleet commented on Nov 26, 2026 Design landed — PR #15495 (open, unmerged, for Felix)
Record: doc/2026-11-26T09-00-00Z_design_id15482_tenant_data_split/ (+ doc/README.md index line), checked against main 65e69239a and the landed HW sources (user-do.ts, bridge-store.ts, export.ts, wrangler.toml).
Decisions (design §1/§3):
Migration/consistency (§5): one write path, no dual-write (registry row in the tenancy DB is the placement fact), movement only by #5869 export/replay, read-at-watermark freshness, budget ladder meters both planes, never-central list untouched.
Implementation (§7): E6 #12801 (adapter), #15483 (contract/budget/manifest), E3 #12798 (sync ingress), and one new slice filed — #15494 (rehome + migration + two-source export), sub-issue of #9080, blocked_by #12801 and #15483 (edges verified by readback). #15494 not enqueued: queue broker unreachable (amd-6 down, #15131); reason recorded on #15494.
All three acceptance criteria are mapped in design §9. This issue is done when PR #15495 merges; left open for Felix's merge + done check.
developing-today-fleet commented on Nov 26, 2026 Evaluation: this design under the owner ruling — tenant data moves to per-tenant D1
Owner ruling 2026-11-26 (on #14866, comment 7189808145; superseding note on #9079, comment 7189808896): everything moves to Cloudflare with D1 as the database; Turso targets are superseded, including tenant data. That ruling is exactly the superseding mechanism this record's §4 named ("a superseding ruling recorded on #9079 or #5681"), so §4's "no per-tenant family in D1" is superseded, and the Turso placements in §1/§3 are retargeted. This comment is the evaluation; the revised implementation slice is #15538, which supersedes #15494's target. No doc PR in this pass — the evaluation fits here and in #15538's body, and a doc-lineage amendment for #9083 §7 is an acceptance item on #15538 so it lands with the implementation record, not ahead of it.
Topology chosen: one D1 database per tenant
One D1 database per tenant, created by the tenancy plane via the Cloudflare API at provisioning; the tenancy directory — itself one platform-only D1 database under the same ruling — holds the tenant → database_id mapping (tenant_db registry row, backend = d1). The tenant's data path reaches its database only through a Worker binding: the binding IS the credential boundary; no per-tenant API token, connection string, or password exists.
Checked against Cloudflare's documented limits (fetched 2026-11-26):
- Limits (https://developers.cloudflare.com/d1/platform/limits/): Workers Paid — 50,000 databases per account, 10 GB max per database (cannot be increased), 1 TB total per account (increasable on request); the page itself says D1 "is designed for horizontal scale out across multiple, smaller (10 GB) databases, such as per-user, per-tenant or per-entity databases." A footnote on the same page caps a single Worker script at ~5,000 D1 bindings (script metadata) — see the binding-mechanics caveat below.
- Pricing (https://developers.cloudflare.com/d1/platform/pricing/): scale-to-zero; Workers Paid includes 100,000 databases before $0.10/database-month (note: the pricing page's 100,000 and the limits page's 50,000 disagree — flag for re-check at scale; both are far above near-term tenant counts), first 25B rows read / 50M rows written monthly included, storage $0.75/GB-month past 5 GB, empty database ≈ 12 KB.
Binding mechanics, honestly: one global Worker statically binding every tenant does not scale past ~5,000 tenants and must not be built. The binding is delivered per tenant via Workers for Platforms — the tenant's User Worker is uploaded with its own D1 binding, and D1 custom bindings (https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/configuration/custom-bindings/ — D1 listed as available) let the Platform Worker intercept query() and enforce per-tenant scoping from props the User Worker cannot read or modify. Fallback: pooled Workers each holding a shard of tenants' bindings. Rejected as the data path: the D1 REST API from a Worker holding an account token — that reintroduces a broad bearer credential; the account API token lives only in the tenancy/provisioning plane (create/delete), never in a tenant path.
Alternatives compared
- Single shared D1 with
tenant_id scoping — rejected. D1's 10 GB per-database cap becomes a 10 GB cap for all tenants combined; a cross-tenant SQL path exists by construction; one compromise is every tenant. It is the shared-DB alternative design(pm-stack): tenancy architecture — per-user Turso databases + central tenancy DB, served by Workers and Durable Objects #9083 already rejected, made strictly worse.
- Shared D1 + per-tenant D1 only for large tenants — rejected. Two topologies and two code paths forever; the shared pool keeps the aggregate cap and the blast radius; the shared→own move is precisely the hard migration; and per-tenant databases cost nothing at small scale, so the hybrid buys nothing.
The credential story — #9083 §7, amended
§7's model (short-lived, audience-scoped, per-(tenant, database) Turso tokens; jti revocation; no token values centrally; issuance gated on account/binding/tenant_db state) cannot apply to D1 literally — D1 has no per-tenant scoped credential, which was §4 reason 2. Under the ruling, §7 is amended in effect, with its guarantees preserved by different mechanisms:
- Audience scoping becomes structural: the binding names exactly one database; there is no bearer artifact to replay against another tenant's DB.
- The leak window disappears as a category: there is no per-tenant credential to leak. The only bearer credential is the platform's account-level API token, held solely by the tenancy plane — §7's own carve-out for the platform management credential.
- Issuance gating survives unchanged in order and place: provisioning/dispatch refuse unless account, binding and
tenant_db are active, checked cheap-first at the front door.
- Revocation: suspension = front-door refusal + unbinding; deletion = refuse first, then drop the database (the §4 step-10 ordering survives).
credential metadata becomes audit-only on the D1 path.
- Genuinely lost, named: direct endpoint access and embedded replicas. Native peers can no longer hold a scoped DB credential; they sync only via Worker routes carrying signed LogSync envelopes — which is what design(pm-stack): tenancy architecture — per-user Turso databases + central tenancy DB, served by Workers and Durable Objects #9083 already decided sync is. The public DB's short-TTL read tokens become read-only Worker routes / a read binding in a public-reader Worker.
Per-family mapping (this record's §1, retargeted)
| Family |
Was (this record) |
Now |
| Signed events and heads |
Per-user Turso; DO = ingress session state |
Per-tenant D1; DO role unchanged |
| KV |
UserDO SQLite |
Unchanged |
| Blob references |
Per-user Turso; bytes in R2; DO serving index |
Per-tenant D1; bytes still R2; DO index unchanged |
| Usage / metering |
DO detail; tenancy-DB rollup |
Unchanged, except the rollup's home is now the tenancy D1 |
| Export state |
UserDO SQLite |
Unchanged |
| World journals |
Per-user Turso (world primary) |
Per-tenant D1; >10 GB worlds shard (below) |
What happens to this record's Turso-premised decisions
- Rebuildable ingress state in UserDO: unchanged. The premise never depended on the backend.
- Dual-watermark export: unchanged in shape — tenant-store watermark (now D1's) + DO state watermark, both stamped, both replayed.
- Read-at-watermark freshness: unchanged as the id: design: serverless storage contract (from #5681) #5863 contract; on D1 it is implemented against the tenant database's primary / session bookmark instead of a Hrana session.
- The growth argument weakens — stated plainly. §3.1 moved the log to Turso partly to escape the DO's 10 GB ceiling. Per-tenant D1 has the same 10 GB hard cap, and it cannot be increased. What the move buys is a separate 10 GB for the log, apart from the DO's 10 GB of working state — not a higher ceiling. A tenant outgrowing 10 GB of log shards across multiple D1 databases or sinks cold data to the home-lab tier (design(id): serverless edition storage — D1 vs Turso vs both for
id on Cloudflare Workers #5681 §5.1 escalation, direction inverted: there is no bigger D1 database to escalate to), and the 1 TB account total binds the aggregate.
- Migration rules (§5): unchanged, kept verbatim in impl(id): rehome hosted tenant event log and blob references onto per-tenant D1 — D1 retarget of the #15482 tenant-data split (supersedes #15494's Turso target) #15538. Movement only by id: design: backup, recovery & exit for serverless storage (from #5681) #5869 export/replay, one write path, no dual-write, registry flip, drain after one retention interval. The D1 topology forces no change to them.
Blockers re-evaluated
Needs a decision before implementation
- Felix: impl(pm-stack): E6 — tenant DB store adapter in id-store (#9083) #12801 — retarget, split (a D1/
store_traits conformance slice), or close as superseded-in-part.
- Felix/Drewry: record the design(pm-stack): tenancy architecture — per-user Turso databases + central tenancy DB, served by Workers and Durable Objects #9083 §7 amendment in the doc lineage (acceptance item on impl(id): rehome hosted tenant event log and blob references onto per-tenant D1 — D1 retarget of the #15482 tenant-data split (supersedes #15494's Turso target) #15538) — the ruling authorizes it; the written amendment should not stay tribal.
- Implementation spike on impl(id): rehome hosted tenant event log and blob references onto per-tenant D1 — D1 retarget of the #15482 tenant-data split (supersedes #15494's Turso target) #15538 must confirm Workers for Platforms custom bindings for D1 vs the pooled-Worker fallback before provisioning work starts.
— Felix (agent felix), evaluation + filing pass: no code, no deploys, no data movement.
MetadataMetadataapp/idPackage/app: id (pkgs/ or apps/ in this repo)effort/mMedium: expected under 1 day of workkind/designA design proposal (design-architect): multi-step, phased, decision-bearingmeta/enrichedIntake review done: acceptance criteria, links, and normalized labels addedpriority/normalOrdinary priority (the default)status/needs-triageNot yet triaged; needs a first look DevelopmentNo branches or pull requestsIssue actions
|