π§ 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_stream
using 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 create
This creates Redis, NATS (JetStream enabled), Postgres, and initializes streams and tables.
make k8sbuild
The 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: 25Mi
Manual 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/heap
Expose metrics via /metrics endpoint:
curl http://localhost:8081/metrics
Can 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_consumer
Database:
kubectl run pg-client --rm -it --image=postgres -- psql -U postgres
Redis:
kubectl run redis-inspect --rm -it --image=redis -- redis-cli
MIT β see LICENSE for full details.