Delivered remotely for a business based in Prague, Czech Republic. Names withheld by agreement.
Project Overview
Real-money sports prediction contests place unforgiving demands on state consistency: a millisecond difference around match kickoff separates a valid slip from an invalid one, and every entry fee or prize payout must reconcile to the last decimal. Working with a gaming operator in Prague, we built a cross-platform contest ecosystem comprising React Native apps for iOS and Android, a React web application, and a transactional Laravel backend deployed on Google Cloud. Players join scheduled fixture pools, submit multi-match predictions against clear scoring rules, monitor live leaderboard movement, and manage real-money balances with full audit traceability.
Business Bottleneck
Peak activity in sports contests does not arrive smoothly; it compresses into the final ten minutes before major European kickoffs, followed by a second surge the moment final whistles blow. Legacy contest scripts relied on non-transactional balance updates and client-trusted timestamps, creating exposure to duplicate entry debits on flaky connections, post-kickoff submission exploits, and manual spreadsheet reconciliation whenever matches were postponed or abandoned. Operations teams needed automated lifecycle controls and deterministic financial accounting before scaling contest volume.
Architectural Strategy
We structured the platform as a single authoritative Laravel domain core consumed identically by React Native mobile clients and the React web portal via Laravel Passport OAuth2 tokens. Financial integrity rests on an immutable double-entry ledger inside MySQL rather than mutable balance columns alone. Contest scoring and payout execution run on isolated background queues with idempotent state machines so upstream fixture updates, tie-breaking splits, and cancelled-match refunds resolve predictably without blocking player traffic.
Core Capabilities
- Multi-Fixture Contest Lobby: Players filter upcoming prediction pools by sport, entry tier, prize structure, and lock countdown across mobile and desktop.
- Server-Locked Prediction Slips: Entries validate against contest eligibility, maximum entries per player, and authoritative UTC kickoff boundaries before debiting funds.
- Double-Entry Wallet Ledger: Deposits, entry stakes, cancelled-contest refunds, and tournament winnings write balanced journal entries with complete statement exports.
- Live Scoring & Tie-Break Engine: Configurable point matrices score outcomes, bonus multipliers, and tie-breaker criteria automatically as official match statuses finalize.
- Contest Operations Console: Administrators configure contest templates, adjust provisional states, handle voided fixtures, and audit user ledger histories from a gated React interface.
- Verified Transaction Notifications: SendGrid delivers signed entry receipts, tournament rank summaries, and payout confirmations triggered strictly after ledger commit.
Technical Architecture
Flow: React Native / React SPA -> Laravel Passport OAuth2 -> Laravel Contest & Ledger API -> Cloud SQL (MySQL) -> Queue Workers -> SendGrid
Upon login, both React Native and React clients authenticate against Laravel Passport to obtain scoped OAuth2 access and refresh tokens. All contest mutations pass through dedicated Laravel FormRequest validators and service classes wrapped in DB::transaction(). When a participant enters a contest, the ledger service acquires a pessimistic row lock (lockForUpdate()) on the user's wallet summary row, verifies sufficient settled funds, appends balanced debit and contest-escrow rows, and records the prediction slip atomically.
Fixture ingestion jobs update match statuses (scheduled, live, provisional, final, void) independently from payout jobs. Once all fixtures in a pool reach final, a queued settlement job computes final ranks, applies dead-heat prize splits where tied participants share pooled tiers, and writes idempotent payout ledger entries keyed by (contest_id, entry_id, payout_type). SendGrid dispatch listeners subscribe only to post-commit domain events, ensuring players never receive a payout confirmation email for a rolled-back database transaction.
Technology Stack
| Category | Technology detail |
|---|---|
| Mobile Clients | React Native (iOS & Android shared prediction slip and live leaderboard UI) |
| Web Application | React SPA for desktop bracket management and wallet history |
| Core API & Domain | Laravel (PHP 8) handling contests, scoring rules, and ledger transactions |
| Database & Ledger | MySQL with InnoDB row locking and immutable double-entry ledger tables |
| Authentication | Laravel Passport OAuth2 tokens for mobile and web client sessions |
| Background Queues | Laravel Queue workers on Google Cloud for scoring and prize payouts |
| Cloud Hosting | Google Cloud Compute Engine, Cloud SQL, and managed load balancing |
| Email & Receipts | SendGrid transactional API for entry confirmations and settlement statements |
Engineering Trade-offs & Solutions
| Challenge | Architectural Solution |
|---|---|
| Double-spend or negative balances under concurrent taps | Pessimistic InnoDB row locks (SELECT ... FOR UPDATE) paired with an immutable double-entry ledger inside single MySQL transactions |
| Post-kickoff prediction tampering | Authoritative server-UTC cutoff checks executed inside the Laravel submission transaction, ignoring client device clocks |
| Duplicate payouts from retried queue workers | Deterministic settlement keys enforced by MySQL unique constraints so retried jobs turn into safe idempotent no-ops |
| Late match corrections or abandoned games | Multi-stage provisional to settled state machine with automated escrow refund jobs for voided contests |
| Divergent business rules across web and mobile | Single versioned Laravel API backing both React Native and React clients with shared DTO serialization |
Security & Reliability
Real-money workflows demand strict boundaries between player actions and administrative overrides. Laravel Passport scopes separate player endpoints from internal contest-operations and settlement routes, reinforced by role-based policies and audit logging on every manual state intervention. Input payloads undergo strict whitelist validation, and CSRF/CORS policies lock browser origins for the React web portal. Cloud SQL runs automated daily backups with binary-log point-in-time recovery enabled, giving finance administrators exact replay capability if an external payment webhook requires investigation. SendGrid templates strip sensitive internal identifiers and sign transactional emails via SPF and DKIM records.
Performance & Scale
Pre-kickoff traffic spikes hit read-heavy lobby endpoints and write-heavy slip-submission endpoints simultaneously. To keep lobby browsing responsive while wallet writes serialize safely per user, contest metadata and countdown schedules are served from short-lived cache layers invalidated on contest state transitions, while wallet locks scope strictly to the individual participant's wallet row rather than global tables. Leaderboard calculations execute incrementally in background workers as fixtures conclude, serving pre-ranked pages directly from indexed MySQL summary tables to thousands of concurrent mobile viewers. React Native clients apply optimistic slip drafting locally and issue compact diff payloads only upon final submission, reducing redundant payload chatter across mobile connections.
Operational Outcomes
Consolidating web and mobile contest rules behind one transactional Laravel core eliminated discrepancies between desktop and phone prediction slips. Finance and contest operations teams gained an auditable double-entry ledger and automated void/refund handling, replacing error-prone manual reconciliations. Players experience reliable pre-kickoff slip confirmation, transparent rank calculations, and prompt post-match prize settlement across both React Native and React web interfaces.