Jungle Wallet
A wagering wallet in Go where the database itself guarantees the balance never drifts from the ledger.
My role
All of the code, infrastructure and CI/CD. Public repository.
- 232
- req/s on a 2 vCPU VM
- 29.8 ms
- p95
- 0
- reconciliation mismatches
Problem
The challenge was to process BET, WIN, LOSS, REFUND and ROLLBACK from several providers, over HTTP and an SQS FIFO queue, without lost updates, negative balances or double processing.
Solution
Go with Uber Fx and pgx (explicit SQL, no ORM), PostgreSQL 17, SQS and SNS FIFO and Keycloak for OIDC. Money is an int64 in cents, and an AST test bans floats across all internal code.
Highlights
- Invariants in the database, with an append-only ledger, a continuous version and balance chain, and a DEFERRABLE constraint trigger that checks at commit time that the balance matches the latest entry.
- Idempotency through an RFC 8785 canonical hash, shared by HTTP and the queue.
- A REFUND that arrives before its BET is parked and resolved when the BET lands.
- A per-wallet ordered outbox with fencing tokens.
- CI with 10 gates (-race tests, system tests that SIGKILL mid-commit, E2E, Trivy, CodeQL and Gitleaks), Cosign-signed images and deploys over Tailscale with rollback.
Result
Sustained 232 req/s on a 2 vCPU VM running the whole stack, with a 29.8 ms p95 and zero reconciliation mismatches. Live at jungle.lab.fredzol.io.