iGaming Wallet Architecture: Double-Entry Ledgers and Balance Management

A casino wallet is not merely a table with one numeric balance per player. It is a financial state machine that records why money moved, protects each business operation from duplication, and makes it possible to reconstruct a balance after incidents, disputes, and delayed provider messages. The architecture must also distinguish an accepted wager from a pending authorization, an informational event from an accounting entry, and a wallet balance from a promotional or reserved amount.

The safest design begins with accounting invariants and the business identity of each transaction. A particular database, event bus, or service framework comes later. This article describes a conceptual double-entry ledger, atomic booking and holds, the optional role of event sourcing, and tests that make the guarantees observable.

Wallet services, accounts and balance types

A wallet service accepts financial instructions from authorized platform components or external game providers through a controlled integration boundary. It validates the instruction, checks the applicable account and currency, applies policy, and produces a durable outcome. The response should describe the committed or rejected business operation, not merely whether an HTTP request reached a server.

Accounts have distinct roles. A player liability account represents funds owed to the player; a clearing or counterparty account records the other side of a transfer; a promotional account may represent funds governed by a separate policy; and a holding account may represent funds not yet available to wager. The accounting model must be designed with finance and compliance requirements for the relevant product and jurisdiction.

Useful balance categories include available (eligible for a new spend under policy), reserved (temporarily committed to an unsettled operation), pending (awaiting an external or internal finalization), and promotional (subject to specific conditions). These labels are not interchangeable; their arithmetic and transfer rules need explicit definitions. A system may maintain them as projections over ledger entries, transactional aggregates, or a combination, but it should be able to explain each figure.

Money should be represented using an exact decimal or integer minor-unit model appropriate for the currency, never an uncontrolled binary floating-point approximation. Persist currency identity with every transaction and account. Transfers across currencies require explicit conversion and valuation records; they should not be hidden inside a generic balance update.

Double-entry ledger model and invariants

Illustrative balanced journal entries for a bet and win
Figure 1. Each example posting has equal and opposite changes in the simplified account view.

In double-entry accounting, each economic operation produces linked postings whose amounts balance within the applicable accounting scope. A simplified internal transfer for a €5 bet might decrease the player’s available position by €5 and increase a corresponding clearing position by €5. A subsequent €12 win would have the opposite effect between relevant accounts. The example is intentionally schematic; production debit/credit directions depend on the chart of accounts and financial reporting model.

The important invariants are independent of programming language:

  1. Every committed business transaction has one stable identity and a complete set of postings.
  2. The postings of a transaction balance under the defined accounting rules and currency scope.
  3. No repeated request for the same logical transaction creates a second financial effect.
  4. A reversal is a new, linked correcting transaction, not a silent deletion of the original record.
  5. Balance projections can be reconciled to the authoritative journal and can be rebuilt or independently verified.

For a concrete example, assume a player has an available €100 before a round. A settled €5 bet leaves €95. A separate €12 win linked to the same round yields €107. A duplicate delivery of the €12 win must leave the balance at €107, not €119. A retry of the original bet after its response was lost must leave it at €107 rather than charging another €5. These examples make idempotency observable as a balance and journal invariant.

Transaction metadata should include an internal transaction ID; an external provider reference; operation type; round reference; account IDs; amount and currency; event or booking timestamps; decision status; and links to an original transaction for refunds or rollbacks. Avoid assuming a provider’s transaction identifiers are globally unique: scope them to provider, environment, tenant, and operation context as required by the contract.

Atomic booking, holds and finalization

Wallet holds and settlement state transitions
Figure 2. A reservation changes availability before final settlement; timeout is not a terminal financial status.

Atomic booking means a committed transaction cannot appear only halfway in the ledger. If an operation requires several postings plus an idempotency record and a balance projection, the chosen storage transaction or coordination design must preserve the agreed invariants. Independent writes to separate stores without a recovery protocol create a gap where the caller can observe success but the ledger cannot prove the complete result.

One practical design uses a database transaction to lock or conditionally update the affected account aggregate, check policy and sufficient funds, insert balanced postings, store the idempotency outcome, and commit. The exact locking mechanism depends on the storage system and contention model. Database isolation is not a substitute for business-key uniqueness; two parallel duplicate callbacks must converge to one committed business operation.

A hold reserves availability without treating every reservation as a final wager. For example, a player with €100 may reserve €5, showing €95 available and €5 reserved. Finalization turns the reservation into the appropriate committed transaction under the agreed model. Cancellation releases it. A hold needs a stable reservation ID, an explicit expiry or recovery policy, and rules for the case where a late finalization arrives after cancellation.

Not every game integration exposes holds, and introducing them without contract support can add complexity. Some providers use immediate bet booking followed by a settlement or rollback. The wallet should implement the actual business contract rather than overlaying an imaginary reservation state onto every provider.

At the API boundary, distinguish received, in progress, committed, and rejected, where those states are applicable. “Timed out” describes what a caller observed; it does not prove whether the ledger committed. Before reattempting a financially sensitive request, use the same business key, a status lookup, or a controlled reconciliation procedure.

Event sourcing as an optional persistence pattern

Event sourcing stores a sequence of domain events that can reconstruct the state of an aggregate. A ledger stores accounting postings with financial invariants and audit meaning. They can coexist, but the terms are not synonyms. An event called BalanceChanged is not automatically a balanced accounting journal; a ledger posting does not necessarily capture the full decision history of a game round.

Event streams versus accounting entries

Difference between wallet ledger and event stream
Figure 3. Operational/domain events can describe ledger facts without replacing the ledger’s accounting guarantees.

A wallet might store authoritative journal entries in a transactional database and publish events such as BetPosted, WinPosted, or RefundRecorded through a transactional outbox. Consumers use those events to update dashboards, notification systems, or analytical views. If the event is delivered twice, the consumer deduplicates by the committed transaction ID; the wallet does not execute the bet twice just because the event was replayed.

Alternatively, an event-sourced wallet can use an append-only event stream as part of the authoritative model, provided the design enforces the necessary accounting invariants, concurrency control, identity rules, and audit requirements. Event sourcing alone does not provide double entry, safe overdraft handling, or exactly-once financial mutation. Those are separate properties that require explicit implementation and verification.

Snapshots may speed reconstruction but should not become an unexplained second source of truth. A reproducible projection must define event versions, ordering within an aggregate, migration rules, and what happens when older events are read by a newer schema. Historical correction should preserve the record of what was originally posted and why a compensating transaction was later authorized.

Consistency, dispute prevention and auditability

The hardest wallet failures occur when each participant believes a different result. A provider may record the wager as accepted while the operator sees an ambiguous timeout. An analytics stream may lag behind the ledger. A player may see a pre-settlement screen after the wallet has already posted the win. Different read models can be temporarily inconsistent without the authoritative financial state being wrong, but teams need to know which difference is expected and which is an incident.

Reconciliation compares internal wallet transactions against provider records using stable mapping keys, transaction types, currencies, amounts, statuses, and time windows. It should identify missing entries, duplicates, delayed operations, and inconsistent reversal references. A discrepancy should lead to investigation or a controlled correction workflow with permissions and evidence—not an ad hoc database edit made simply to align two totals.

An audit trail should answer: who or what initiated the instruction; what contract and configuration applied; what validation occurred; what journal entries were committed; whether the operation was a retry; what external acknowledgment was returned; and what later correction, if any, changed the economic position. Sensitive player and security data should be minimized and protected while preserving the evidence genuinely required for the operation.

Consider a late refund. The system must know the original transaction, how much remains refundable, whether a prior refund already occurred, and whether the round is in a state where reversal is allowed. It must record the new correction transaction atomically and prevent a duplicated refund from producing a second credit. Deleting the original debit would destroy the history needed to explain the dispute.

Architecture example and design validation checklist

A practical wallet boundary consists of an authenticated transaction API, idempotency and validation logic, an authoritative ledger store, optional held-funds logic, a repeatable balance projection, an outbox for committed domain events, and a reconciliation feed. Deployments may combine several of these into one service. Separation is useful only where it preserves or clarifies the financial guarantees.

Before accepting the design, validate these cases in an automated integration environment:

  • A bet succeeds once, and the caller receives the same business outcome after resending the same stable transaction identifier.
  • Two concurrent duplicate requests produce a single committed financial effect.
  • A bet rejected for insufficient available funds has no accidental partial postings.
  • A commit succeeds but the HTTP response is lost; the subsequent retry does not create a second debit.
  • A win is delayed, then booked once with a durable relationship to the round and original bet.
  • A refund is issued twice with the same business reference; the second attempt is repeat-safe.
  • A process crashes between journal commit and event publication; the committed event is eventually made available without duplicate financial effects.
  • A projected balance is recomputed from journal data and agrees with the materialized value within the defined rules.
  • A historical correction leaves an explainable chain of original and compensating entries.
  • A reconciliation job identifies a provider-wallet mismatch without silently “fixing” the balance.

The right wallet design is one whose invariants survive concurrency, partial failure, network retries, and operational repair. A fast balance endpoint is valuable; a balance that cannot be explained is not. Begin with identities, journals, and testable guarantees, then choose the deployment topology that allows those guarantees to be maintained.

Scroll to Top