Skip to content

id: design: Currency scaling — autoscaling service, Redis → multi-Turso → TigerBeetle path #5676

Open

Description

@dezren39

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

  1. 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.
  2. 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.
  3. 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.
  4. 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

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:

  1. Currency backend port (interface) + invariant test suite contract.
  2. Stage A design: Redis-backed hot store + regular-store system of record, write-through, crash recovery & reconciliation.
  3. Autoscaling design: stateless front-end, hot-account mitigations, scaling triggers.
  4. 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.
  5. Stage C design: TigerBeetle adapter mapping + Stage B→C migration/cutover plan.
  6. 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.
  7. 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

  1. added
    source/creatorFiled by the new-issue-creator job
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    on Nov 4, 2026
  2. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    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.

  3. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  4. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    task/triageQueue packet kind: verify, reproduce, and route this item
    and removed on Nov 5, 2026
  5. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · triage complete

    • Agent: queue worker (repo-worker-code), lane code-j
    • Session / ID: task 10109
    • Found via: queue claim (coverage-audit requeue)

    Triage of issue #5676 at current main (verified fresh 2026-11-05):

    Scoped path / ordering (no implementation is scoped from #5676 itself):

    1. id: design: currency backend port + invariant test suite contract (from #5676) #5823 first — the backend port + invariant suite is the contract every stage adapter must satisfy; it gates id: design: Stage A: Redis hot store + regular-store system of record (from #5676) #5824/id: design: Stage B: multi-Turso sharding by currency (from #5676) #5826/id: design: Stage C: TigerBeetle adapter + B→C cutover (from #5676) #5827.
    2. id: design: Stage A: Redis hot store + regular-store system of record (from #5676) #5824 (Stage A) and id: design: currency autoscaling design (from #5676) #5825 (autoscaling) next, in parallel.
    3. id: design: Stage B: multi-Turso sharding by currency (from #5676) #5826 (Stage B) after Stage A; its conversion coordination builds on id: design: conversion engine — linked transfer pairs, rate authorisation, liquidity accounts #2063 (closed).
    4. id: design: conversion & RateAuthorisation across stages (from #5676) #5828 depends on id: design: RateAuthorisation as a signed ID-graph object — schema, signing, revocation #2290, which is user/escalated — that dependency is blocked on Drew's recorded decision there, not on engineering.
    5. id: design: Stage C: TigerBeetle adapter + B→C cutover (from #5676) #5827 (TigerBeetle) last; id: design: currency load & correctness verification programme (from #5676) #5829 (verification programme) runs across all stages.

    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.

  6. 22 remaining items

  7. added
    priority/lowNice to have; do when convenient
    effort/lLarge: multi-day or open-ended; expect staged check-ins
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    on Nov 14, 2026
  8. dezren39 commented on Nov 14, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · 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.

    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).

  9. dezren39 commented on Nov 14, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · duplicate packet — #5676 already triaged earlier today

    • Agent: repo queue worker, lane any-c (repo-worker-code)
    • Session / ID: cron repo-queue-worker-shift-any-c run 2026-11-14; task 16840

    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.

  10. added 2 commits that reference this issue on Nov 16, 2026
  11. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    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.

  12. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    Agent note — lane any-y, task 19859

  13. removed their assignment
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/lLarge: multi-day or open-ended; expect staged check-insepic/id-programReprioritization program epic (2026-11-12)kind/designA design proposal (design-architect): multi-step, phased, decision-bearingpriority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobstatus/triagedTriaged and routed (see agent note)task/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions