Open source

Personal2026open source

Jungle Wallet

A wagering wallet in Go where the database itself guarantees consistency between balance and ledger.

232

requests per second on a 2 vCPU VM

29.8 ms
95th percentile latency
0
reconciliation mismatches

The problem

A wagering wallet receives bets, wins, losses, refunds and rollbacks from several providers, over HTTP and an SQS FIFO queue, and has to process them with no lost updates, no negative balances and no duplicate processing, even with out-of-order messages and failures in the middle of a transaction.

The solution

Go with Uber Fx and pgx (explicit SQL, no ORM), PostgreSQL 17, SQS and SNS FIFO and Keycloak for OIDC. Monetary values are integers in cents, and a test over the syntax tree forbids floating-point numbers across all internal code.

Technical notes

  1. Invariants enforced 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.

  2. Idempotency through an RFC 8785 canonical hash, shared by HTTP and the queue.

  3. A refund received before its bet is held and resolved when the bet arrives.

  4. A per-wallet ordered outbox with fencing tokens.

  5. Continuous integration with 10 verification stages, including system tests that kill the process mid-commit and Cosign-signed images.

Outcome

The service sustained 232 requests per second on a 2 vCPU VM running the whole stack, with a 29.8 ms 95th percentile and no reconciliation mismatches.