Skip to content

Payments and Integrations Practical engineering guide

Sportsbook Wallet Architecture: Ledgers, Holds and Integrity

Design sportsbook wallet operations with balanced postings, scoped identities, atomic reservations, uncertainty handling and operation-level reconciliation.

Explore the flow Worked examples · Failure handling · Primary sources
Explore this guide

A sportsbook wallet should record financial operations and reservations in a consistent ledger, then derive spendable balances from those records. A mutable balance alone cannot explain duplicate callbacks, partially matched orders, outstanding withdrawals or later corrections.

This guide is for engineers designing transaction integrity. Its signed amounts, states and pseudocode are illustrative operational models, not a certified accounting system or jurisdiction-specific financial advice. Qualified accounting and regulatory review must establish the actual requirements.

Define the invariants before selecting a database

Write down what must remain true under concurrency, retry and restart. Examples include one intended financial effect per operation, no spending of reserved funds, balanced postings within a currency and traceable corrections.

The authoritative balance can be derived from postings while a transactional projection supports efficient authorization. A display cache is a different object. If a cached figure disagrees with the ledger, investigate and restrict the affected operation rather than editing history until the numbers appear equal.

Separate account funds, bonus restrictions, holds and risk exposure. Their relationship depends on the product's rules. A lay stake, for example, is not the same amount as standalone lay liability; portfolio offsets must not be assumed without an approved calculation.

Assign ownership of each invariant. The wallet service can enforce funds constraints, but the order system must provide reliable matched/cancelled state and finance must own reconciliation decisions.

Technical flow

Sportsbook Wallet Architecture: Ledgers, Holds and IntegrityIllustrative logical boundaries; provider contracts and operating requirements determine the implementation.
  1. 01Verify operation

    Bind trusted account, currency, amount and immutable operation identity

  2. 02Check + reserve

    Enforce funds and risk constraints consistently under concurrency

  3. 03Post atomically

    Commit balanced postings and operation evidence in one transaction

  4. 04Publish + reconcile

    Deliver repeatably through an outbox and resolve external uncertainty

The diagram follows an authenticated intent into validation, a transactional operation/posting boundary and downstream evidence. It does not require every box to be a separate service.

RecordPurpose
Operation identityRecognize a repeat and detect conflicting reuse
Posting entriesExplain the financial movement and its opposite side
ReservationKeep pending commitments out of available funds
Domain referenceLink payment, bet, round or adjustment to its origin
Outbox/audit evidencePublish a committed change and preserve accountability

The payment lifecycle guide explains provider eligibility and deposit/payout workflows. This article examines the wallet boundary that those workflows rely on.

Represent money and balanced movements explicitly

Choose fixed-precision amounts and a currency-specific scale supported by your product/provider. Integer minor units can work where the scale is defined; do not assume every currency or asset has two decimal places. Avoid binary floating-point arithmetic for authoritative amounts.

Store currency on every operation and posting. A conversion links separately balanced currency legs with an explicit rate and rounding policy; amounts in different currencies must not be added into one meaningless zero-sum check.

In an illustrative signed-unit model, moving 30 units from a player's available bucket to their held bucket creates −30 available and +30 held. The pair sums to zero within that currency while total player funds remain unchanged. This is a reservation movement, not proof that a provider paid out or that the operator earned revenue.

Actual accounting account types, debit/credit conventions and reporting treatment require the applicable accounting design. The operational invariant is that each intended movement is complete and traceable.

Give operations a stable identity and bind the payload

Use a uniqueness scope that matches the real source: tenant/account boundary, provider namespace and documented operation reference where applicable. A game round can contain several operations, and a provider's callback request ID may describe a delivery rather than the financial effect.

Store the accepted operation's normalized identity and meaningful payload. A repeat with the same reference and same effect can return the recorded result. The same reference with a different player, amount or currency must be a conflict, not an instruction to return a success that belongs to another operation.

apply_operation(authenticated_scope, request):
    validate_account_authority_and_supported_amount(request)
    transaction:
        existing = find_operation_in_verified_scope(request.identity)
        if existing:
            require_same_financial_payload(existing, request)
            return existing.result
        lock_relevant_wallet_state()
        verify_funds_and_domain_preconditions()
        insert_unique_operation()
        append_balanced_postings()
        update_authoritative_projection()
        insert_committed_event_outbox_record()
    return recorded_result

This pseudocode describes one possible boundary. It is not a complete database implementation, and a provider's external deduplication guarantees remain separate from your local uniqueness rule.

Make balance checks and reservations atomic

Two withdrawals can both observe a 100-unit balance before either writes. If they reserve 70 and 50 independently, the combined commitment becomes 120. A correct design must serialize or reject conflicting work so the second decision sees the appropriate remaining capacity.

PostgreSQL transaction-isolation documentation describes transaction behavior and retry considerations. Its locking documentation explains row-level locking. These are available mechanisms, not evidence that an arbitrary transaction wrapper automatically protects a wallet.

Select a locking/version strategy and test all participating paths, including administrator adjustments and asynchronous callbacks. Use a consistent acquisition order where operations touch multiple accounts. Handle conflicts, deadlocks and serialization failures with bounded retries of the complete valid transaction.

Do not hold a database transaction open across a slow external provider call merely to pretend both systems share atomicity. Persist local intent/hold first, submit through the provider contract and reconcile uncertainty.

Model holds through their complete lifecycle

A reservation should identify its source, amount/currency, current status and resolution evidence. Expiry policy must distinguish a request never submitted from one that may have executed externally.

StateAvailable-funds implicationResolution needed
Reserved, not submittedAmount is heldSafe local cancellation under policy
Submitted, outcome unknownKeep relevant commitmentAuthoritative external query/report
Confirmed financial effectConsume the applicable holdDurable result and posting
Confirmed failure/cancellationRelease only the resolved partEvidence that commitment no longer exists

For an illustrative 100-unit request with 40 matched and 60 unmatched, cancellation of the unmatched 60 does not release the matched 40. An order timeout or browser disconnect is not a supported reason to erase the whole commitment.

Distinguish reservation age from proof of failure. Alert on old holds and route them to reconciliation. Automatically releasing every old record can create spendable funds while a payout or bet remains active elsewhere.

Bridge committed changes to other services

After a local wallet transaction commits, downstream order, reporting or notification systems may need an event. A direct database write followed by a separate publish can fail between the two.

AWS's transactional outbox guidance describes persisting an event with the local change and delivering it separately. Consumers still need repeat-safe behavior; an outbox is not an exactly-once guarantee for external systems.

Keep event identity, relevant ordering scope and delivery/processing evidence. Distinguish “committed in the ledger,” “published,” and “applied by a consumer.” A message acknowledgement does not establish financial settlement.

If a read model is lost, rebuild it from supported durable evidence. A previously acknowledged consumer position does not prove its cache survived. See the payment webhook guide for a concrete inbox/outbox crash review.

Corrections and reconciliation

Append authorized compensating operations instead of changing old postings. Link a correction to the original effect, its reason, actor and supporting evidence. Restrict support access so adjustments use the same balance and uniqueness controls as automated operations.

Reconcile at operation level where reports allow it, then reconcile grouped totals with defined cutoff/timezone. Equal totals can hide two offsetting errors. Classify unmatched references, amount/currency differences, missing transitions and timing differences separately.

Keep provider settlement distinct from player balance. A hypothetical 100-unit gross payment and 3-unit provider fee can produce a 97-unit bank settlement without implying that the player's original credit should be silently rewritten to 97.

Document accounting and operational ownership for unresolved cases. The payment integration service can scope software boundaries; it does not replace provider, finance or legal approval.

Test transaction integrity as a set of properties

Use controlled fixtures and verify final records, not only API responses:

  • Same operation repeated: one intended effect and a consistent recorded result.
  • Same key with a changed amount or player: conflict without a second effect.
  • Concurrent 70/50 requests against 100: no unsupported 120-unit commitment.
  • Crash before/after commit: no partial postings and a recoverable result.
  • Lost external response: unresolved hold remains explainable until reconciled.
  • Partial match/cancel: only resolved exposure is released.
  • Outbox redelivery: downstream consumers remain repeat-safe.
  • Currency mismatch or rounding boundary: explicit rejection/policy outcome.

These are proposed acceptance properties, not results of a live wallet test. Include backup restoration and external activity since the restore point before declaring financial recovery complete.

Frequently asked questions

Is a balance projection forbidden?

No. It can support efficient reads and authorization if updated consistently and reconcilable to authoritative postings. A standalone editable number is the insufficient design.

Can a hold expire automatically after a timeout?

Only under a policy that accounts for the real submission state. A provider timeout can leave the effect unknown, so elapsed age alone is not evidence that funds are safe to release.

Does double entry prove the correct player was credited?

No. Balanced entries can still reference the wrong account or operation. Authorization, payload binding and reconciliation are also necessary.

Does a unique event ID prevent every duplicate financial effect?

No. Distinct events can describe the same effect. Protect the financial operation's identity as well as message receipt.

Can all currencies share a single balance total?

Maintain the applicable currency/asset and scale boundaries. Any conversion needs explicit linked legs and rounding treatment rather than adding unlike units.

Further reading

Primary sources

  1. PostgreSQL transaction-isolation documentation
  2. locking documentation
  3. AWS's transactional outbox guidance