Repository navigation
Description
Extends #2043 (ID currencies v1), #2063 (conversion engine), and #2290 (RateAuthorisation). This is an EXPANSION design: currencies must stay simple to use while the service behind them autoscales with load — and the storage path must evolve without ever breaking double-entry invariants.
Problem
#2043 defines currencies v1. Left open: what happens under real load. A currency system that is correct at demo scale but requires a rewrite (or downtime, or invariant-breaking migration) at production scale fails its purpose. Equally, reaching for the heaviest backend on day one buries a simple user-facing concept under operational complexity. We need an explicit scaling path: simple first, autoscaling always, advanced backends by swap — not by redesign.
Governing principles
- Simple to handle: for users and for client code, a currency is a named balance with transfers in/out. No backend concept (Redis, Turso, TigerBeetle) ever leaks into the user-facing API.
- Autoscale the whole service: not just the ledger store — the whole user-facing currency service (API, conversion, authorisation checks) must autoscale with load: stateless front-ends, horizontal scaling, no single-writer bottleneck in the hot path beyond what double-entry correctness strictly requires.
- Double-entry invariants are backend-independent: every transfer is balanced debits/credits, no negative-balance violations per currency rules, transfers are atomic and idempotent, and the ledger is auditable/replayable. These invariants MUST survive every backend swap unchanged, proven by tests run against every backend.
- Swap, don't rewrite: a backend abstraction (port) with adapters; moving stages is a deployment/migration exercise, not an API change.
The scaling path (stages)
Stage A — Pre-TigerBeetle: Redis-backed currency store + regular store
- Currency balances / hot state in a Redis-backed currency store (fast atomic operations, e.g. Lua-scripted double-entry postings, idempotency keys, per-account locks/striping).
- Currency entities, metadata, and durable records kept in the regular store with the existing mechanisms (the same persistence path the rest of ID already uses) — Redis is the hot/operational layer, the regular store remains the system of record for definitions and history unless the design explicitly rules otherwise; specify the write-through / reconciliation protocol between them, including crash recovery (Redis loss must never lose a committed transfer: define durability, snapshotting/replay from the regular store, and reconciliation jobs).
- Conversion hooks: id: design: conversion engine — linked transfer pairs, rate authorisation, liquidity accounts #2063 conversion engine calls into this stage unchanged; id: design: RateAuthorisation as a signed ID-graph object — schema, signing, revocation #2290 RateAuthorisation checks happen before posting and are recorded with the transfer.
Stage B — Sharded regular-store backends: multiple Turso DBs per currency grouping
- Design the step where the regular store itself shards: multiple Turso databases representing different currencies (or currency groups) — noted honestly as less clean than the ideal: cross-currency transfers then span databases, so the design must specify two-phase / saga-style cross-DB transfers, ordering, failure recovery, and how conversion (id: design: conversion engine — linked transfer pairs, rate authorisation, liquidity accounts #2063) coordinates a transfer whose legs live in different DBs.
- Per-DB autoscaling, connection management, schema versioning across a fleet of DBs, and a directory service mapping currency → DB.
- Migration tooling: moving a currency from one Turso DB to another (rebalancing) with zero-downtime and invariant checks before/after.
Stage C — TigerBeetle (eventual ideal backend)
- Design the TigerBeetle adapter against the same port: account/transfer mapping, TigerBeetle's own double-entry semantics, pending/post/void two-phase transfers, and how ID-level concepts (conversion, rate authorisation, holds) map onto it.
- Migration design Stage B → C: dual-run/shadow posting, ledger comparison, cutover per currency, rollback plan.
- The user-facing API and invariants do not change at this stage — that is the acceptance test of the whole abstraction.
Autoscaling design (all stages)
- Stateless currency-service front-end: any instance can serve any request; state lives in the store layer.
- Load model: define expected hot spots (a single popular currency/account), and mitigations: account striping, batched postings, read replicas / cached balance reads with defined staleness, and queue-based smoothing for bursts.
- Scaling triggers and limits: what metric scales the front-end, what metric signals a store-stage transition (A→B, B→C), and what the cost/ops profile of each stage is.
- Multi-region / latency considerations: state what v-next promises (single-region strongly consistent?) and what it explicitly defers.
Interfaces that must not change across stages
- Transfer API: create transfer (idempotency key, from, to, amount, currency, metadata), query balance, query history, hold/capture/release if supported.
- Conversion integration (id: design: conversion engine — linked transfer pairs, rate authorisation, liquidity accounts #2063): quote → authorised rate (id: design: RateAuthorisation as a signed ID-graph object — schema, signing, revocation #2290) → atomic multi-leg posting, or a specified failure with no partial legs.
- RateAuthorisation integration (id: design: RateAuthorisation as a signed ID-graph object — schema, signing, revocation #2290): who may authorise a rate, audit record of authorisation attached to every converted transfer.
- Events/notifications emitted on posting, so other ID subsystems react identically regardless of backend.
Correctness & verification
- One invariant test suite, run against every backend adapter (Redis stage, Turso stage, TigerBeetle stage): balanced postings, atomicity under injected crashes, idempotent retries, concurrent-transfer race tests, no lost committed transfers on store loss/restart.
- Property-based / model-based testing: random transfer sequences checked against a simple in-memory reference ledger.
- Reconciliation: continuous checker comparing hot store vs. system of record; alerting and repair procedure.
- Load tests per stage with published envelopes (transfers/sec, p99 latency) so the stage-transition triggers are evidence-based.
Decomposition sketch
Follow-on design tickets to be filed from this issue:
- Currency backend port (interface) + invariant test suite contract.
- Stage A design: Redis-backed hot store + regular-store system of record, write-through, crash recovery & reconciliation.
- Autoscaling design: stateless front-end, hot-account mitigations, scaling triggers.
- Stage B design: multi-Turso sharding by currency, cross-DB transfers with id: design: conversion engine — linked transfer pairs, rate authorisation, liquidity accounts #2063 conversion, rebalancing migrations.
- Stage C design: TigerBeetle adapter mapping + Stage B→C migration/cutover plan.
- Conversion & RateAuthorisation integration across stages (id: design: conversion engine — linked transfer pairs, rate authorisation, liquidity accounts #2063, id: design: RateAuthorisation as a signed ID-graph object — schema, signing, revocation #2290) — atomic multi-leg posting per backend.
- Load/correctness verification program: property tests, crash-injection, per-stage performance envelopes.
Open questions
- Is Redis the system of record for anything, or strictly a hot layer over the regular store — and what is the exact recovery story if Redis is lost mid-transfer?
- At what measured load does Stage A stop being sufficient? Define the trigger now, even approximately.
- Multi-Turso per-currency sharding: shard key is currency, currency group, or account range — and who operates the currency→DB directory?
- Cross-currency conversion atomicity in Stage B: true two-phase commit, saga with compensations, or a single coordinator DB for conversion legs?
- TigerBeetle timing: is Stage C a committed destination or an option to keep open — what must Stage A/B avoid doing that would block it?
- Balance-read consistency: may balance reads ever be stale (cached), and if so what does the UI promise users?
Program note: expansion-style design — a later pass breaks this into the follow-on design tickets above, then implementation tickets. Relatives: #2043, #2063, #2290.
Activity
dezren39 commentedon Nov 5, 2026
Gap pass (WS-F, 2026-11-04): this issue's decomposition sketch is now filed.
Each follow-on design ticket named in the sketch above was filed as its own issue (label
app/id), so the acceptance item “Follow-on design tickets filed from the Decomposition sketch” can now be checked:Exception, where applicable: any sketch item already answered by a later filing is noted in the pass worklog rather than duplicated. Design prioritisation is now independent per ticket; implementation timing is a separate decision.
dezren39 commentedon Nov 5, 2026
🤖 Agent note · picked up
dezren39 commentedon Nov 5, 2026
🤖 Agent note · triage complete
Triage of issue #5676 at current main (verified fresh 2026-11-05):
source/creator,app/id); no hard-stop labels, no code defect to fix and nothing already merged that closes it.queue/blocked+user/escalated(a Drew-owned decision, not touched here); id: design: conversion engine — linked transfer pairs, rate authorisation, liquidity accounts #2063 CLOSED; id: design: RateAuthorisation as a signed ID-graph object — schema, signing, revocation #2290 OPEN withuser/escalated.Scoped path / ordering (no implementation is scoped from #5676 itself):
user/escalated— that dependency is blocked on Drew's recorded decision there, not on engineering.Blockers recorded: the only hard dependency blocker in this set is #2290 (
user/escalated) feeding #5828. Design prioritisation per child ticket is independent (per the gap pass); implementation timing is a separate decision. Issue #5676 stays open as the umbrella until its children land — closing it now would lose the tracking point, and no evidence supports closing it as done.22 remaining items
dezren39 commentedon Nov 14, 2026
🤖 Agent note · triaged
triaged.State found (revalidated fresh, 2026-11-14): this expansion design is fully decomposed and its base is real. Nothing is unfiled; the issue stands as the umbrella.
pkgs/id(registry/factory/gateway issues id(currency): currency registry schema + ledger-u32 allocator (from #2062) #2317–id(currency): PoC — registry + factory + gateway, single-currency issue→transfer (from #2062) #2321, RateAuthorisation id(currency): RateAuthorisation + revoke schema types and fold in pkgs/id (Phase 1 of #2290) #3800–id(currency): quote issuance + binding for RateAuthorisation (Phase 3 of #2290) #3802, client API id: implement: pkgs/id currency client API — the §7 app-facing function surface from #2041 (gated on #2251 spec) #2803). This is a scaling-path design over a shipped v1, not a greenfield proposal.Disposition: no new issues or tasks are filed from this triage — the decomposition is complete, and the open children carry their own design work through the queue individually. This issue remains open as the umbrella over #5823/#5825/#5826/#5827/#5828 and closes when the stage designs land (or when a stage is explicitly dropped, per the children's own records). Labels applied: kind/design, priority/low, effort/l (app/id and epic/id-program already present) — low priority matches the expansion-design framing: the path must be designed before load forces it, and no production load signal is currently driving it.
Task 15274 completes as
triaged, follow_up_task_ids [] (all follow-ons already filed as the issues above).dezren39 commentedon Nov 14, 2026
🤖 Agent note · duplicate packet — #5676 already triaged earlier today
Task 16840 duplicates task 15274 (same lane, this shift), which triaged #5676 today (note 6877125192): the decomposition is complete and verified — children #5823/#5825/#5826/#5827/#5828 open, #5824/#5829 closed — and the umbrella stays open as the programme home. Since then, this shift also triaged the keystone child #5823 (task 16767) and enqueued its design pass (task 16878). #5676 re-verified OPEN. Task 16840 completes as
already_done; no changes made.Design Stage C: TigerBeetle adapter + B→C cutover (from #5676)
Merge pull request #10797 from developing-today/queue/13037-5827-stag…
dezren39 commentedon Nov 17, 2026
agent-note:v1
task: 18332
lane: code-d
state: triaged
worker: repo-worker-code
finding: Fresh 2026-11-17 triage of bulk-intake task 18332 for issue #5676 (Currency scaling design parent). Issue #5676 is OPEN, carries status/triaged (triage of record: task 15274, note 6877125192, 2026-11-14; duplicate task 16840 completed already_done the same day), and no hard-stop labels. The design is fully decomposed into children #5823-#5829. Fresh child states this shift: #5823 CLOSED, #5824 CLOSED, #5825 CLOSED, #5826 CLOSED, #5827 CLOSED, #5829 CLOSED - and the sole remaining open child is #5828 (conversion & RateAuthorisation across stages), which carries status:in-review, i.e. it is actively being handled on its own track.
next: No follow-on packet is owed from this parent: every child exists and is tracked, and #5828 is in review. Issue #5676 stays OPEN as the programme umbrella until #5828 closes. Task 18332 completes as triaged naming the existing triage of record.
dezren39 commentedon Nov 17, 2026
Agent note — lane any-y, task 19859