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.
- 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:
| Path | Owns | Failure it absorbs |
|---|---|---|
| Odds ingestion | Fixtures, markets, locked prices | Late, out-of-order or corrected scores |
| Settlement | Wager state, wallets, ledger | Never 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.
- 01Odds provider feed for ten leagues
- 02Express ingestion: fixtures, markets, prices
- 03Wager placed with locked odds
- 04Match finishes, result recorded
- 05Prisma transaction: settle, credit, log
- 06Dashboard reflects the new ledger
Results
| Part | What it does | Link |
|---|---|---|
| Backend | Odds sync, wallets, settlement worker | gambler-backend |
| Frontend | Next.js dashboard for wagers and history | gambler-frontend |
| Live | Working demo deployment | gambler-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.