Skip to main content

How to Build a Sports Betting Website from Scratch

This is a complete guide to building a functional sports betting website — from architecture decisions to deployment. By the end, you will have a working site that displays live odds, accepts bets, and settles them automatically. Tech stack: React frontend, Node.js backend, PostgreSQL database, FieldFunded API for odds and settlement.

Architecture Overview

Three layers, clean separation:
  • Frontend: Displays odds, handles bet slip UX, shows account history
  • Backend: Proxies API calls, validates bets, stores data, runs settlement
  • External: FieldFunded API for odds data and settlement, PostgreSQL for state

Step 1: Database Schema

Before writing any code, define your core tables:

Step 2: Backend — Odds Proxy

Never expose your API key to the frontend. Proxy all calls through your backend:

Why Proxy?

  • Your API key stays on the server — never in client JavaScript
  • You can add your own caching layer (reduces API usage by 80%+)
  • You control rate limiting per user
  • You can transform/filter data before sending to the frontend

Step 3: Backend — Bet Engine

The core business logic — validate bets, deduct balance, store records:
Key points:
  • FOR UPDATE locks the user row to prevent race conditions on balance
  • Transaction wraps deduction + bet creation + audit log atomically
  • Validation happens server-side (never trust the frontend)

Step 4: Frontend — Event Browser

Display events grouped by sport with real-time odds:

Step 5: Frontend — Bet Slip

The bet slip is the checkout experience — keep it simple and clear:

Step 6: Automatic Settlement (Cron Worker)

This is the part most tutorials skip. Run a cron job every 60 seconds to settle finished bets:
This worker:
  • Polls all pending bets from your database
  • Sends each to the settlement endpoint for resolution
  • Credits the user balance on win or refund (transactionally)
  • Logs every settlement for auditing
  • Handles errors gracefully — failed checks retry on the next cycle
For a deeper dive on the settlement logic and edge cases (partial settlement, dead heats, voided markets), see the Build a Settlement Engine guide.

Step 7: Player Props Display

Player props are the fastest-growing market category — users expect to bet on individual player performance (points, rebounds, assists, goals, cards), not just match outcomes. The odds response already includes player prop markets alongside standard markets:
A typical NBA game returns 200+ player prop markets. Soccer matches include goalscorer, cards, and shots props. Player props settle automatically through the same settlement worker — no extra code needed. For a dedicated tracker, see the Player Props Tracker guide.

Step 8: Live Scores

Show real-time scores alongside your odds. The scores endpoint is lightweight and optimized for frequent polling:
Scores include period breakdowns — quarters for basketball, halves for soccer and american football, sets for tennis, and map scores for esports (CS2, LoL, Valorant). Poll every 30-60 seconds during live events.

Step 9: Parlay Support

Parlays (accumulators) are the highest-margin product on any sportsbook. Let users combine multiple selections into a single bet:
Parlay settlement uses the same settlement API — check each leg individually. If any leg loses, the parlay loses. If a leg is refunded (voided match, postponement), that leg is treated as odds 1.00 and the parlay continues with the remaining legs. See the Parlay Calculator guide for the full resolution logic. Let users find specific teams, players, or matchups instantly:
Search works across all sports — soccer, basketball, american football, tennis, esports, and more. Users can search by team name (“Arsenal”, “Lakers”), competition (“Champions League”, “NFL”), or even specific matchups (“Arsenal vs Chelsea”).

Step 11: Deployment Checklist

Total cost to launch: under $25/month.

Rate Limit Math

The Starter plan at $29/month covers this comfortably. With aggressive caching (5-10s TTL on odds, 30s on scores), you can serve hundreds of concurrent users on a single API tier.

Security Considerations

Before going live, implement these:
  • Hash passwords with bcrypt (never store plaintext)
  • Rate limit your own API endpoints (express-rate-limit)
  • Validate all inputs server-side (never trust frontend data)
  • Use HTTPS everywhere (Cloudflare provides free SSL)
  • Store API keys in environment variables, never in code
  • Add CSRF protection for bet placement
  • Implement responsible gambling limits (daily/weekly deposit caps)
Running a real-money betting platform requires gambling licenses in most jurisdictions. This tutorial covers the technical implementation only. Before accepting real money:
  • Consult a lawyer specializing in gambling regulation
  • Obtain the required licenses for your target markets
  • Implement KYC (Know Your Customer) verification
  • Add responsible gambling tools (self-exclusion, deposit limits)
For play-money or educational platforms, no license is typically required.

Get Your Free API Key

Start building today — 10,000 free requests/month

See Pricing

All plans compared — from free to enterprise