iGaming lab
API-backed demo

Scratch Cards

REST · sealed symbol state
Server-backed gameNext Standalone
Loading Scratch Cards runtime…
engineering.case-study

Inside the Scratch Cards system boundary.

What the player experiences, what the implementation actually owns, and where production responsibilities would begin.

01

Game background

Scratch cards are instant-win games that reveal a concealed symbol layout. From a software perspective, the important problem is preserving the sealed outcome while allowing progressive, authorized reveals without leaking unrevealed symbols.

02

How the game works

  1. Create a card with a virtual stake.
  2. The server seals nine weighted symbols before the first reveal.
  3. Reveal cells individually or request the remaining cells.
  4. When the card is complete, matching symbol groups are evaluated and the payout is returned.
03

Backend architecture

The NestJS service keeps a ScratchCardsGame and activity timestamps in an in-memory session map. Unrevealed cells are masked in API state; reveal commands expose only the requested server-owned symbols.

ClientREST APISealed sessionCrypto symbolsRevealPayout
04

System boundaries

Game Client
Presentation, input, accessibility, and demo-credit display.
REST API
Request validation and routing into one isolated game session.
Game Session
Ephemeral configuration and the previous authoritative result.
Game Engine / RNG
Outcome generation, game rules, win evaluation, and result contracts.
Reveal Boundary
Which sealed cells may be exposed in each response.
05

Critical engineering decisions

  • Generate and seal the card server-side before interaction starts.
  • Never send unrevealed symbols in the public state contract.
  • Prevent bet changes after reveal begins.
  • Use weighted symbols and an explicit paytable so outcome math is testable independently of the UI.
06

Failure handling

  • A duplicate reveal returns the already-known cell rather than generating a new symbol.
  • An expired gameId is rejected because the sealed card no longer exists.
  • A disconnect can resume only while the in-memory session remains available and the client retains gameId.
  • The demo deducts and credits locally; a production implementation would need an idempotent wager and settlement ledger.
07

Fairness / RNG

Weighted symbols are created with backend cryptographic random bytes. The sealed state prevents the browser from choosing outcomes, but there is no public commitment/proof protocol or certification layer.

08

Conceptual data model

CardSession- gameId- betAmount- createdAt- lastActivity
Card- symbols- revealed- status
CardWin- symbol- count- multiplier- payout