Keep balances server-authoritative
A player browser must never be allowed to increase its own balance. Payment confirmation, admin adjustment and contest rewards should call protected backend endpoints that derive the trusted user and tenant from the authentication token.
Firebase rules are a second line of defense, not a substitute for ledger logic. Deny direct client writes to authoritative wallet and ledger nodes.
Use an append-only ledger
Each balance movement should identify the wallet, amount, direction, reference, timestamp and metadata. Cached balances make reads fast, while reconciliation compares them with ledger totals.
Use idempotency references for payment webhooks. A repeated provider callback must not create another credit.
Handle joins and refunds
A paid join combines wallet debit, slot reservation and participant creation. Design the failure order before release. If a later step fails, reverse the earlier financial movement and preserve an audit record.
Refunds should be explicit ledger entries rather than deleting the original debit. That preserves the event history needed for support.
Limit administrator power
Replace arbitrary balance editing with signed adjustments that require a reason. Show the resulting balance and write an audit entry containing the acting staff UID.
Separate player withdrawal requests from owner payouts. Each flow has different approval, settlement and refund rules.
Frequently asked questions
Is a database transaction enough for wallet security?
No. Transactions prevent concurrent balance races, but you also need authorization, idempotency and ledger reconciliation.
Should failed entries be deleted?
Keep an audit status or compensating refund entry instead of erasing financial history.
Build your tournament workspace
Create a private draft, test the real workflow and publish only when ready.
Create Free Webapp