01 — Context
Several of a company's apps needed in-app currencies (coins, points, tokens). Each would otherwise have built its own balance logic.
02 — Challenge
Balances had to be correct, auditable and isolated per app, with expiring credits, safe retries and no cross-app leakage.
03 — Approach
Each app a registered client
One ledger service where each app is a registered client authenticated with service credentials and owns its own credit types and reason codes.
Lots, expiry and safe retries
Credits are stored in lots with optional expiry. Debits use the soonest-expiring lots first, idempotency keys make retries safe, and a sweeper expires old lots.
Units, not currencies
Amounts are positive integers in each credit type's own unit. Money is handled upstream, so the ledger never converts currencies.
Spec-first and tested for real
Spec-first, with a spec-integrity check and integration tests against a real database in containers. It includes an admin front end.
04 — Outcome
The first consumer app passed its conformance suite against the live ledger in staging.

