Blog · 25 November 2026 · 1 min read
Pelivahti: settling bets in real time and still agreeing with the books
A stream that settles bets, flags harmful play within seconds, and must match a batch rebuild to the cent. All players and bets are synthetic.
Project: Pelivahti · live dashboard
Can a stream settle bets correctly, flag harmful play within seconds, and still agree with the books? Pelivahti is my attempt to prove it can. Every player and bet in it is synthetic.
Try the dashboard: filter by product and region, click an alert rule, or query the marts with SQL.
Two consumers, one truth
Sports bets and casino rounds stream through Redpanda. The first consumer settles them into an append-only wallet ledger in real time and checks each player against responsible gaming rules. The second lands every raw event in Delta Lake, and dbt rebuilds the ledger from scratch.
The rule is strict: the streamed ledger and the rebuilt ledger must agree to the cent. If they do not, something is wrong with one of them, and the test says so.
Time is harder than money
Responsible gaming rules work on windows, such as losses in the last hour. Events arrive late and out of order, so windows are based on event time with watermarks, and late events are handled explicitly rather than dropped.
Exactly-once without transactions
Kafka transactions add complexity. Instead, every ledger write carries the source offset, and writes are idempotent. To prove it, a crash test kills the consumer mid-batch, restarts it, and checks that the ledger still matches the rebuild.
Contracts at the door
Each event type has a versioned data contract. Anything that does not match goes to a dead-letter queue instead of poisoning the ledger, and the pipeline keeps running.
From ledger to reports
Revenue and gambling tax marts sit on top, covered by 46 data tests.
What I would do differently
I would build the batch rebuild first. Having the "slow but certainly right" answer early made every streaming bug obvious within minutes.
Code: GitHub