From 24c98f79fe8353ca00cc11843251d4798c07be7d Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Sun, 8 Nov 2026 12:06:10 -0600 Subject: [PATCH] doc: backup, recovery & exit decision record for serverless storage (#5869) --- doc/2026-11-08_design_id5869.md | 227 ++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 doc/2026-11-08_design_id5869.md diff --git a/doc/2026-11-08_design_id5869.md b/doc/2026-11-08_design_id5869.md new file mode 100644 index 000000000..d6d8d3f98 --- /dev/null +++ b/doc/2026-11-08_design_id5869.md @@ -0,0 +1,227 @@ +# Design: backup, recovery & exit for serverless storage + +- Date: 2026-11-08 +- Status: **decision record** — the backend-agnostic design is decided + (§2–§6). Every backend-specific parameter is expressed as a hook the + #5863 storage contract must expose, with a decision rule (§7), so + this record does not guess or constrain the backend choice that + #5867 / #5681 own. +- Issue: [#5869](https://github.com/developing-today/code/issues/5869), + follow-on of [#5681](https://github.com/developing-today/code/issues/5681) + (serverless edition storage — D1 vs Turso vs both), programme epic + #2056. Serverless edition itself: #2046. Signed journal replication: + #806. +- Siblings consumed, not re-decided: [#5863](https://github.com/developing-today/code/issues/5863) + (the serverless storage contract — journal append/read, world state, + indexes — that this record builds its recovery and export on), + [#5864](https://github.com/developing-today/code/issues/5864) / + [#5865](https://github.com/developing-today/code/issues/5865) + (per-backend journal-fit spikes, which establish what each backend + can expose), [#5866](https://github.com/developing-today/code/issues/5866) + (local-dev parity — its fixture replay rides the export mechanism + defined here), and [#5868](https://github.com/developing-today/code/issues/5868) + (cost & limits — retention windows below are requirements it prices, + not numbers it may silently shrink). +- **Boundary against #5867.** #5867 owns choosing the backend and + migrating live data to the chosen backend. This record owns + backup, point-in-time recovery, open-format export, and provider + exit. Where #5867's migration tooling reuses the export bundle + (§4), it consumes it as a format; the guarantees the bundle must + carry are fixed here. **Parent-decision impact: none** — nothing in + this record changes a decision #5681 carries; if a future backend + cannot expose a §2.3 hook, that is a #5681-level conflict and must + be recorded there, not worked around here. + +## 1. The one idea everything follows from + +The signed journal (#806) is the system of record; every backend +store is a materialisation of it. Backup, recovery, and exit are +therefore all the same operation at different speeds: **capture the +journal (plus a world-state snapshot as an accelerator), move it in +an open format, and replay it somewhere independent.** Provider +features may accelerate any step, but no step may *depend* on a +provider feature — a recovery path that needs the provider you are +recovering from is not a recovery path. + +## 2. Decision: point-in-time recovery is journal replay + +1. **PITR target.** Any point in the retained window is recoverable + at **journal-entry granularity**: recovery means "world state as + of journal sequence *N*" (equivalently, the last entry at or + before timestamp *T*). There is no coarser snapshot-only target. +2. **Retention window (contract requirement).** The journal is + retained online for **at least 30 days**; world-state snapshots + are taken **daily and retained 90 days**, and **weekly snapshots + are retained 1 year**. An export bundle (§4) taken at any snapshot + is retained independently of the provider for at least 1 year. + #5868 prices this; implementation may exceed it, never undercut + it without amending this record. +3. **Storage-contract hooks each backend must expose** (the backend- + specific half of PITR, stated as #5863 contract requirements): + - a **monotonic journal sequence** visible to readers, with a + timestamp per entry; + - **snapshot + delta read**: a consistent world-state snapshot at + a named sequence, plus journal entries after it; + - **replay-in**: append/replay of exported journal entries into an + empty store, preserving sequence, timestamps, and signatures; + - **schema/contract version** stamped on every snapshot and + export, so a restore never silently crosses a version boundary. +4. **Provider-native PITR is an accelerator, never the mechanism.** + D1 Time Travel, Turso point-in-time restore, and their successors + may be used for operator convenience inside their windows, but + drills (§6) must prove the journal-replay path works without + them. A backend whose native PITR is the *only* way to reach a + point in the window fails this record. +5. **Restore shape.** Restore = provision an empty store behind the + contract → load the newest snapshot at or before the target + sequence → replay journal deltas to the target → run the §6 + verification before the store serves traffic. Restores are + always to a fresh store, never an in-place rewind of the live + one; the live store is evidence until the restore is verified. + +## 3. Decision: what a backup is + +A backup is an **export bundle (§4) taken on schedule**, not a +provider snapshot. Provider snapshots may exist as an operational +extra, but the daily/weekly artefacts that satisfy §2.2 are bundles +held outside the provider's control (separate account/bucket and, +for the weekly, separate provider or offline storage). A backup +that only the provider can read back is a copy, not a backup. + +## 4. Decision: the open-format export bundle + +1. **Shape.** A bundle is a directory (or single archive) containing: + - `manifest` — contract/schema version, journal sequence range, + snapshot sequence, per-file checksums, entry counts, and the + journal signatures needed to verify provenance (#806); + - `journal/` — journal entries in canonical newline-delimited + JSON, in sequence order, split into numbered segments; + - `snapshot/` — world state at the snapshot sequence, expressed + in contract terms (the same form #5866 fixtures use), not as a + backend-native database file; + - `blobs/` — large payloads, content-addressed, referenced from + journal/snapshot by hash; + - `README` in-bundle — format version and the restore procedure, + so the bundle is self-describing without this repo. +2. **Completeness guarantee.** Everything reachable through the + #5863 contract — every journal entry, every world-state record, + every blob — is in the bundle, byte-for-byte restorable, with + **no lossy type mappings**: values are encoded in the journal's + canonical types, never through a provider type that cannot + round-trip (provider-specific rowids, timestamps without zone or + precision, floats standing in for decimals are the canonical + failures this rule exists to forbid). +3. **What a bundle deliberately does not contain:** derived indexes + (rebuilt on restore), provider-internal replication state, + credentials or secrets (referenced by name only, re-provisioned + at restore), and uncommitted/in-flight writes (the bundle ends + at a committed journal sequence, named in the manifest). +4. **Rejected alternatives:** + - *Backend-native dumps as the canonical export* (a D1 SQLite + file, a sqld dump): they tie the exit to one backend's format, + bypass journal invariants on re-import, and cannot be replayed + into the other candidate backend — they are #5867 migration + inputs at best, not this record's export. + - *Provider snapshots as the backup:* unreadable outside the + provider, so they fail the exit requirement by construction. + - *Continuous cross-provider replication as the exit strategy:* + it pre-decides a standing second backend (a #5867/#5681 call), + doubles the cost surface #5868 must price, and still needs this + export for the day both replicas share a bug. + +## 5. Decision: the provider-exit runbook + +Exit is a rehearsed procedure (§6 drills), executed in this order: + +1. **Declare and freeze.** Announce the exit; set the source store + read-only at a named journal sequence *F* (the exit point). +2. **Export.** Take a full bundle at *F* (§4). Verify checksums and + signatures against the manifest before touching anything else. +3. **Restore into the independent target.** Provision the target + (the other backend, a self-hosted store, or local — independence + from the exiting provider is the requirement) and restore per + §2.5 to sequence *F*. +4. **Verify before cutover.** Replay-equivalence: target world state + at *F* matches the source's declared state at *F* (the #5866 + oracle check); journal signatures verify; record counts and blob + hashes match the manifest. Any mismatch aborts the exit with the + source untouched. +5. **Cut over.** Point the edition at the target; run read traffic, + then writes. The source stays read-only and intact. +6. **Point of no return.** Only after the target has served verified + production traffic for a full snapshot cycle is the source + eligible for teardown. **Teardown — or letting source-side + retention lapse — is the point of no return**, and it is a + separate, explicit action, never a step that happens by expiry + during the exit window. +7. **After exit.** The exit bundle and the verification record are + retained for at least 1 year; the exit is not "done" until a + post-exit drill restores from the exit bundle alone. + +## 6. Decision: restore verification and drills + +- **Every restore verifies.** No restore — drill, recovery, or + exit — is complete until replay equivalence and signature checks + (§5.4) pass; a restore that "probably worked" is a failed restore. +- **Monthly:** automated restore drill — restore the latest daily + bundle into an independent (non-provider or other-provider) + target and run the verification. Drill failure is an incident, + not a backlog item: PITR is broken until a drill passes. +- **Quarterly:** full exit rehearsal — §5 steps 1–5 against a + scratch target, timed; the measured duration is recorded on + #5869's successor tracking issue, because an exit that takes + longer than the provider-risk window it protects against is a + design input to #5681, not a surprise. +- **On change:** any change to the journal format, the contract + version, or either backend adapter requires a passing drill + before it ships (the drill is that change's regression test, + with replay equivalence as its oracle). + +## 7. Backend-specific parameters: decision rule, not a guess + +The hooks in §2.3 are the contract; how each backend satisfies them +is settled mechanically once #5867 lands, and recorded as an +addendum to this record (the addendum may not weaken §2–§6): + +- **D1:** sequence/timestamps from the journal tables the contract + owns (never D1-internal bookmarks); snapshot+delta via contract + reads; Time Travel usable only as a §2.4 accelerator. +- **Turso / libSQL:** the same contract-owned journal; native + point-in-time features likewise accelerators only; embedded + replica files are never the export form (§4.4). +- **Both:** each backend independently satisfies every hook and + passes the same drill; "the other backend has it" is not coverage. + +## 8. Invariants implementation must hold + +- **E1 — Exportable without loss.** Every stored record is + exportable in the §4 format without lossy types and restorable + byte-for-byte; a type that cannot round-trip may not be admitted + into storage through the contract. +- **E2 — Verifiable independence.** An exit is verifiable by + restoring a bundle into a target independent of the source + provider and proving replay equivalence — before teardown, every + time. +- **E3 — No provider-only path.** No backup, recovery, or exit step + depends on provider-only tooling; provider features accelerate, + they never gate. +- **E4 — Journal is truth.** Snapshots and materialised state are + accelerators; any conflict between a snapshot and the signed + journal resolves in favour of the journal. +- **E5 — Frozen exit point.** An exit or PITR restore names its + journal sequence; nothing after that sequence leaks into the + restore, and nothing before it is missing. +- **E6 — Secrets by reference.** Bundles contain no credentials; + a restore re-provisions secrets by name at the target. +- **E7 — Drills or it didn't happen.** Recovery capability exists + only while the §6 drills pass; a lapsed or failing drill means + the capability is reported as absent, not assumed. + +## 9. What this record does not do + +It does not choose or migrate the backend (#5867), define the +storage contract (#5863 — it states hooks the contract must +expose), set cost guardrails (#5868 — it states windows #5868 +prices), or implement any backup/export/restore code. Implementation +issues, when filed, cite the invariant (§8) or step (§2/§5/§6) they +realise.