π§ Work in Progress β This evolving real-time betting engine is built for speed, scalability, and live insights. Some features are experimental or incomplete, with active exploration into resilience, profiling, and autoscaling.
A fast, horizontally scalable betting engine designed for real-time ingest, aggregation, and performance visualization β powered by Go, NATS JetStream, PostgreSQL, Redis, and Kubernetes.
β‘ Built for speed. π Tuned for stats. π§ Optimized for concurrency.
- JetStream + Queue Groups: Load-balanced message consumption with durable delivery
- PostgreSQL-backed storage: Accurate persistence of betting data with automatic failover
- Redis Odds Engine: Lightweight odds update logic using atomic Redis counters
- Live Stats Dashboard: WebSocket-powered UI with real-time metrics, trends, and failure insights
- Kubernetes Native: Full deployment stack with autoscaling via Horizontal Pod Autoscaler (HPA)
- pprof & Prometheus hooks: Built-in memory profiling and metrics scraping for performance tuning
| Layer | Stack |
|---|---|
| Language | Go 1.24 |
| Messaging | NATS JetStream |
| Database | PostgreSQL |
| Key-Value | Redis |
| UI Dashboard | HTML + WebSocket + Vanilla JS |
| Orchestration | Kubernetes (HPA enabled) |
| Observability | pprof, Prometheus-ready /metrics |
| Container | Docker & Kubernetes-ready images |
- Bets are published to the
bets_streamusing JetStream (e.g., via simulator) - Backend pods subscribe to the stream via QueueSubscribe, enabling horizontal scaling
- Each bet is:
- Persisted to the database
- Used to update Redis-based odds
- Emits stats.update messages to
stats_stream
- Stats Aggregator merges per-pod metrics and feeds the WebSocket dashboard
- The dashboard presents live totals, per-second rates, and health indicators
make createThis creates Redis, NATS (JetStream enabled), Postgres, and initializes streams and tables.
make k8sbuildThe backend consumes bets, stores them, and updates stats. The aggregator merges pod stats and serves the WebSocket API.
go run load-simulator/main.go 10 1000β Sends 1,000 bets at 10ms intervals.
Visit the Real-Time Dashboard to see:
- β Total bets processed
- π΅ Bet volume
- π Odds updates
- π§― Redis & DB failure metrics
- π¨ Color-coded accuracy bars
- π WebSocket status banner
Pods auto-scale based on memory usage:
HorizontalPodAutoscaler:
minReplicas: 3
maxReplicas: 5
target:
averageMemory: 25MiManual scaling also supported:
kubectl scale deployment betting-engine-backend --replicas=5- Enable memory profiling:
curl http://localhost:6060/debug/pprof/heap
go tool pprof http://localhost:6060/debug/pprof/heapExpose metrics via /metrics endpoint:
curl http://localhost:8081/metricsCan be scraped by Prometheus + visualized in Grafana.
Use make reset to purge bets, odds, and stream history.
Streams:
nats stream info bets_stream
nats consumer info bets_stream bets_consumerDatabase:
kubectl run pg-client --rm -it --image=postgres -- psql -U postgresRedis:
kubectl run redis-inspect --rm -it --image=redis -- redis-cliMIT β see LICENSE for full details.