A casino game round looks simple on a player’s screen: accept a wager, determine a result, and show the outcome. Internally, that single interaction spans a game service, an operator wallet, a provider integration, and often asynchronous messaging. When an acknowledgement disappears or a worker restarts, a vague status such as processing cannot explain whether the wager was taken, the result was computed, or the award was credited. A game round state machine makes those distinctions explicit.
A state machine is not merely a diagram. It is an enforceable agreement about which business transitions are legal, what evidence is needed to advance, and which transitions must never happen twice. It is particularly valuable for an iGaming platform because the system must preserve player-facing continuity without changing authoritative financial history.
This article presents a conceptual server-side model for a single-wager round. A multi-step bonus, an unsettled live-dealer event, or a jurisdiction-specific rollback rule may require additional substates. The names below are examples, not a universal provider standard. What matters is that every name has a precise meaning and the implementation enforces it.

Why a formal state model matters
The danger of an informal workflow is not that one programmer forgets to set a flag. It is that two services interpret the same flag differently. A callback handler might treat done as “outcome generated,” while a support dashboard interprets it as “money settled.” A retry worker might see failed and create a new debit even though the original debit committed. If each service makes a locally reasonable guess, the platform can end up with globally inconsistent facts.
A formal model asks three questions for every transition: what was true before, what evidence was obtained, and what must be true afterward? The evidence should be durable and identifiable: a committed ledger transaction, a persisted outcome record, an accepted reversal, or an operator-approved resolution. A successful HTTP response alone may be insufficient when the remote system’s commit semantics are unknown.
The round is a business aggregate, not a substitute for the wallet ledger. It references separate bet and settlement records that have their own immutable identifiers. One round can move through states while the underlying ledger remains the independent financial authority. That separation makes reconciliation possible: the round claims a stake was accepted, and a query can independently verify the corresponding posting.
Formal models also improve product behavior. A player who reconnects after an ambiguous timeout should see a pending or recoverable round, not a new opportunity to submit the same stake as if nothing happened. A completed animation can be replayed in the UI without replaying a financial operation. The browser owns presentation state; the server owns round state.
States, transitions and terminal outcomes
A reasonable minimal model starts with CREATED, representing a durable round identity and a validated session context, before a wager has been posted. BET_PENDING means a debit or reservation has been requested but its authoritative result may be unknown. BET_ACCEPTED means the platform has evidence that the intended debit or reservation committed. OUTCOME_RECORDED means the authoritative outcome has been persisted against a specific game configuration and round identity. SETTLEMENT_PENDING means the terminal award or no-win closure is being finalized. SETTLED means the model has a fully resolved economic result with no outstanding required posting.
Two alternative paths deserve names of their own. REJECTED is a terminal round with no accepted wager—for example, a stake failing validation before debit. VOID_PENDING and VOIDED represent a permitted cancellation path when an accepted bet cannot be completed; the required compensating postings must be confirmed before VOIDED is asserted. Finally, REVIEW_REQUIRED is a nonterminal exception state or separate operational flag for an ambiguity that automation cannot safely resolve. Do not confuse it with an economic reversal.

A state transition table can make the implied rules testable:
| From state | Trigger and evidence | To state | Forbidden shortcut |
|---|---|---|---|
CREATED |
Server validates stake, session and rules | BET_PENDING |
Computing final outcome with no accepted wager |
CREATED |
Validation definitively rejects the wager | REJECTED |
Recording a debit for a rejected round |
BET_PENDING |
Matching debit or hold is confirmed | BET_ACCEPTED |
Treating a network timeout as a definitive rejection |
BET_ACCEPTED |
Outcome committed under pinned rules version | OUTCOME_RECORDED |
Recomputing a second outcome on retry |
OUTCOME_RECORDED |
Settlement operation is initiated | SETTLEMENT_PENDING |
Reporting final settlement from UI animation |
SETTLEMENT_PENDING |
Financial closure is verified | SETTLED |
Posting a second award from a duplicate callback |
BET_ACCEPTED |
Contract permits cancellation, with reason | VOID_PENDING |
Deleting the accepted stake record |
VOID_PENDING |
Compensating ledger effect confirmed | VOIDED |
Claiming reversal before its commit is known |
For live or bonus games, OUTCOME_RECORDED may contain additional domain steps such as WINDOW_CLOSED, RESULT_PENDING or BONUS_IN_PROGRESS. A single generic FAILED terminal state is often too ambiguous: failure to deliver a response, failure to accept a wager and failure to settle an accepted wager are three different situations.
Every transition must be idempotent under the chosen business identity. If SETTLED is already recorded and the same settlement acknowledgement arrives again, the handler should return the existing result or no-op, not post another award. An event with the same identifier but conflicting amount or currency is not an ordinary retry; it is a contract violation or an integrity incident.
Business invariants and impossible states
Invariants are claims that must hold across all allowed execution histories, including crashes and retries. They are more powerful than a long list of expected happy-path messages because they identify defects that appear only under specific interleavings. At minimum, a single-wager game round should satisfy the following rules:
- A
REJECTEDround has no accepted stake posting. - A
SETTLEDround has one intended accepted stake business action and a fully accounted-for terminal result, whether the award is zero or positive. - Every ledger-affecting business action has a stable identity; the same business key cannot create two economic effects.
- A terminal round cannot silently return to a financial mutation state.
- Outcome records reference a pinned rules/configuration version and the accepted bet context.
VOIDEDrequires evidence of the appropriate compensating action, not only a UI cancellation.
It is tempting to phrase an invariant as “one ledger entry per bet.” In a double-entry or multi-account ledger, the economically correct posting may be represented by several entries. A stronger statement is one intended economic effect per unique business action, with the expected balanced journal entries. The correct uniqueness boundary depends on the ledger’s accounting model.
A particularly dangerous impossible state is SETTLED with an unknown award commit. Another is REJECTED after a confirmed debit without a linked reversal. OUTCOME_RECORDED with a different game_rules_version than the version used at stake acceptance is also suspicious unless the provider contract explicitly permits a version transition. These conditions should trigger a compensating workflow, an incident and audit evidence—not an arbitrary state rewrite.

Consider a concrete failure. A stake of 200 minor units is accepted, but the response to the RGS times out after the operator commits its ledger posting. If the RGS treats the timeout as REJECTED, the round state and wallet truth diverge. Correct recovery queries or replays the same business request key and resolves BET_PENDING using the original result. If the key is reused with a different amount, the operation must be rejected or investigated instead of accepted as equivalent.
An analogous race appears during settlement. The wallet posts a 500-unit award, and the callback acknowledgement is lost. The state machine remains at SETTLEMENT_PENDING, but the next attempt reuses the award identity. The ledger reports its already-committed posting; only then does the round transition to SETTLED. No second payout is created.
Rules can also become mutually incompatible. Suppose two worker processes disagree about the outcome while both hold apparently valid messages. The invariant that one round has one authoritative final outcome should defeat both attempts to write competing results. This is why the outcome identity and versioned round record must be immutable after commitment, rather than mutable fields on a frequently updated session object.
Persistence and concurrent updates
The round state should be stored durably with a revision number, transition timestamp, triggering event ID and references to the evidence that justified the move. If two workers read revision 12 and both attempt to advance it, an optimistic compare-and-swap condition allows only one transition from revision 12 to 13. The losing worker must reload the new record and evaluate whether its event is redundant, late or genuinely conflicting.
This mechanism prevents stale round-state writes, but does not make remote ledger calls atomic with local database writes. The common production pattern is to isolate an idempotent ledger operation, persist its business reference, and use an outbox or durable work queue for follow-up work. Recovery then rechecks the remote posting by the original request identity before claiming success or initiating compensation. Transactional outbox reduces local dual-write gaps; it does not magically create a distributed ACID transaction across providers.

For an HTTP API, conditional updates can use an entity version and the If-Match semantics documented in RFC 9110. Within a database, a versioned update can express the same idea:
UPDATE game_rounds
SET state = 'SETTLEMENT_PENDING', revision = revision + 1
WHERE round_id = :round_id
AND revision = :expected_revision
AND state = 'OUTCOME_RECORDED';
Exactly one affected row indicates that the local transition won. Zero rows means the caller must reread state; it is not permission to bypass verification. Indexes and constraints should also enforce unique round identity, idempotency namespaces and outcome identity. Some implementations use per-round serialization or transactional locking rather than optimistic updates; the invariant is more important than a particular lock primitive.
Event messages require the same discipline. Partitioning by round_id can preserve order within a stream partition, but cross-service messages, callback retries and reconciliation can still arrive late. The consumer should decide validity from persisted state plus event identity, not only arrival order. Ignore acknowledged duplicates, record invalid transitions and preserve diagnostic evidence under policy. Events should carry schema versions so older consumers do not misinterpret new statuses.
A useful operational question is: what does a restart do to a round pending for ten minutes? The answer should be a deterministic recovery policy. A scheduler checks age and evidence, queries authoritative services, resumes idempotently or escalates. It should not simply force all old rounds into FAILED because a dashboard needs a tidy count.
State-machine diagram and transition table
A diagram is a review artifact; a transition table is executable policy. Together they should cover every admitted transition and reject everything else. In code, centralize transition validation rather than scattering conditional checks across HTTP handlers, consumers and cron tasks. The service may expose a command such as advance_round(round_id, expected_revision, event) which returns an explicit outcome: applied, already applied, stale revision, invalid transition or requires review.
Store the intended next action only when safe. If the model is in BET_PENDING, a retry worker can resubmit the same debit key or query the wallet. If the model is in SETTLEMENT_PENDING, a retry worker can reconcile the same award key. If it is in REVIEW_REQUIRED, automatic traffic should not introduce a different economic interpretation without approved evidence and a recorded decision.

For support and audit queries, link the round to an immutable transition journal: previous state, new state, event ID, actor/service, request correlation, evidence reference, time, and policy version. Avoid logging raw tokens, personal details or secret RNG state. A business timeline should make it possible to explain the round without reconstructing the story from unrelated application logs.
Some transitions depend on jurisdiction-specific rules or product contracts. For instance, a cancellation after outcome generation may be prohibited or tightly controlled; bonus-round sequences may settle in installments; live games can legitimately hold wagers while awaiting dealer-confirmed events. Put those constraints in the published model rather than relying on a generic round diagram to resolve every product.
Model-based tests and edge cases
Example-based unit tests usually cover a happy path and one rejected path. Model-based tests generate command sequences and assert that forbidden states never appear, even after duplicates or out-of-order messages. A test harness can maintain a simple reference model, send commands to an in-memory implementation, and compare the resulting state and recorded ledger effects.
Representative cases include double-clicks, the same debit callback twice, a win arriving before the local outcome message, a reconnect after successful debit but lost acknowledgement, a crash after remote award commit, conflicting rules versions, two workers using the same revision, and a late reversal request after settlement. Tests should distinguish permitted resolution from impossible transitions. Randomized model tests are valuable, but preserve failing seeds and event sequences to make defects reproducible in CI.
An end-to-end integration sandbox should inject timeouts after remote commit as well as before it. This is crucial: a timeout before a database write and a timeout after a write look identical at the HTTP client but demand different recovery reasoning. A local fake provider that always fails before committing may produce false confidence.
Use metrics that express unresolved integrity risk: number and age of nonterminal rounds, transitions rejected as impossible, duplicate callback rate, ledger mismatches by business identity and time to evidence-backed resolution. High throughput and low average latency do not demonstrate financial correctness. Reconciliation across round, provider and wallet records remains the independent control.
The final design principle is straightforward: the server never guesses a round’s economic outcome from transport symptoms. It records evidence, admits only valid transitions, and recovers using stable business identities. That discipline makes the platform easier to debug, audit and explain to players without coupling the correctness of money movement to the success of a browser animation.
References and further reading
- RFC 9110 — HTTP Semantics (conditional requests)
- OWASP — Transaction Authorization Cheat Sheet
- Confluent Developer — Event Sourcing
Engineering model only. Exact state semantics, ledger agreements and void rules must be validated against the licensed operator’s contracts and applicable requirements.