← All projects

Backend architecture and frontend

Sports Betting & Automated Settlement

A full-stack wagering platform where odds ingestion and payout settlement are separate pipelines, so a scoring feed outage cannot corrupt a balance.

Full-stackBackend
prisma tx · acid
Global sports leagues handled by one odds pipeline
10
Settlement written as Prisma transactions
ACID
Deployed frontend with a REST backend
Live

The problem

A betting platform is a ledger with a sports feed attached. The feed is unreliable — matches start late, scores arrive out of order, providers send corrections — and money is already committed against the number that arrived first. If settlement runs inside the same loop that ingests odds, one malformed payload can leave a wager half-paid.

The brief was a working platform across ten leagues where the odds path and the money path are separate, and where a settlement either fully commits or does nothing. Split by responsibility:

PathOwnsFailure it absorbs
Odds ingestionFixtures, markets, locked pricesLate, out-of-order or corrected scores
SettlementWager state, wallets, ledgerNever writes a partial balance

Neither path can leave the other half-written, because they meet only at committed database state.

Approach

  • Two pipelines, one database. A Node.js and Express backend owns live odds synchronisation and user wallets, but settlement is a distinct job that reads finished matches rather than reacting inline to every feed event.
  • Separated reads and writes. Odds fetching updates fixtures and locked prices; payout logic reads those fixtures and writes wallet and wager state. A bad score payload can delay a settlement, but it cannot write a partial balance.
  • ACID settlement through Prisma. Each settlement is a Prisma transaction: mark the wager settled, credit the wallet, append the ledger entry. A failure rolls the whole thing back and the job retries.
  • Locked odds. The price a user accepts is stored on the wager, so a later odds refresh cannot silently change what was bet.
  • Next.js dashboard. Active wagers, locked odds, wallet balance and history in one view, talking to the REST backend.
  • Fault-tolerant ingestion. Provider responses are treated as untrusted: matches are matched by external id, duplicate score updates are idempotent, and a failed fetch never blocks the settlement worker.
  1. 01Odds provider feed for ten leagues
  2. 02Express ingestion: fixtures, markets, prices
  3. 03Wager placed with locked odds
  4. 04Match finishes, result recorded
  5. 05Prisma transaction: settle, credit, log
  6. 06Dashboard reflects the new ledger

Results

PartWhat it doesLink
BackendOdds sync, wallets, settlement workergambler-backend
FrontendNext.js dashboard for wagers and historygambler-frontend
LiveWorking demo deploymentgambler-frontend-steel.vercel.app

Ten leagues run through one normalised schema, and the separation means the settlement job can be replayed after an incident without asking the odds provider for anything.

What went wrong

The first version settled inside the ingestion handler, and that was the bug worth keeping: a score correction arrived after a payout, so the ledger and the fixture disagreed with no record of which was authoritative. Moving settlement into its own transaction boundary and treating the feed as eventually consistent fixed the class, not the instance.

The remaining sharp edge is time. A match that never reports a final score holds its wagers open indefinitely, so any real deployment needs an explicit void or manual-review path rather than an unbounded wait. That is the next piece of work, and it is deliberately not hidden behind a "done" label.