TWZNBooking Q4 2026
01Overview
Case03 / 05

A provably fair competition platform built on cryptographic trust.

Full-stack prize competition platform for a UK automotive business — where every draw is transparent, verifiable, and cryptographically secure.

Proof
every draw provably fair, publicly verifiable
Client
Procter Motor Competitions
Industry
Automotive / Prize Competitions
Region
United Kingdom
Stack
Next.jsReactTypeScriptSupabaseStripeVercel
PM Competitions platform screenshot
pmcompetitions.co.uk
02The challenge
Requirements06

The challenge.

The UK prize competition market is crowded — and plagued by scepticism. Entrants routinely question whether draws are legitimate, and operators struggle to prove they are. For a new entrant like Procter Motor, launching into this space without a clear answer to “how do I know this is fair?” was a non-starter.

Procter Motor came to us with a clear objective: build a competition platform for high-value automotive giveaways that people could actually trust. Not through branding or reassurance copy — through verifiable proof.

The platform needed to:

Spec sheet06 req/06 mapped

Off-the-shelf solutions couldn't deliver on the core requirement. They rely on basic random number generation that can't be audited, lack the concurrency controls needed for popular competitions, and treat regulatory compliance as an afterthought. A custom build was the only path.

03The solution
Parts05

The solution.

01

Provably Fair Draw System

Trust was the central design constraint, so we started with the draw engine.

The winner selection system is built directly into the database layer using PostgreSQL's pgcrypto extension — the same cryptographic library used to generate SSL/TLS certificates. The draw logic never touches application code, eliminating any possibility of manipulation at the API layer.

When an admin triggers a draw, four things happen in sequence:

  1. 01

    Cryptographic seed

    A 256-bit cryptographic seed is generated using hardware-backed random number generation sourced from the server's entropy pool.

  2. 02

    SHA-256 hash

    The seed is combined with the competition ID and a precise timestamp, then hashed using SHA-256 — the algorithm that underpins the Bitcoin network.

  3. 03

    Winner selection

    The hash is converted to an index that maps to a specific ticket in the pool. The winning ticket is selected.

  4. 04

    Proof stored permanently

    The complete cryptographic proof — public seed, SHA-256 hash, verification hash, winning index, and algorithm identifier — is stored permanently alongside the result.

A public verification endpoint allows anyone to independently recalculate and confirm the result. No login required. Enter the competition ID, and the system re-derives the hash from the stored seed and metadata, confirms it matches the original, and proves the winner was selected correctly.

No trust required — just maths.

Fig.Provably fair draw
In the databaseVerified
Trigger
Admin
one action in the dashboard
Seed
256-bit hardware entropy
SHA-256
seed + competition + time
Winner
hash → ticket index
Proof stored
seed, hash, index
Anyone, no login
Public verification
re-derive the hash, confirm the winner
6 events · play, or hover a node to trace its path
The entire draw process runs inside the database — the application layer never touches it.
02

Concurrent Ticket Sales

Popular competitions can see hundreds of users purchasing tickets simultaneously. A single duplicate ticket number or a failed allocation under load would undermine the fairness the draw system is designed to protect.

The platform pre-generates a complete ticket pool for each competition at creation time. When a user purchases tickets, the system uses PostgreSQL's row-level locking to atomically claim available tickets from the pool. Each allocation is isolated — concurrent transactions skip locked rows and claim the next available tickets, guaranteeing uniqueness even under heavy load.

If any part of a transaction fails, the entire allocation rolls back cleanly. No duplicate ticket numbers. No gaps in the pool. No race conditions.

Fig.Concurrent ticket claims
User AUser BUser C
User
A
claims 2
User
B
claims 2
User
C
claims 1
Row-level locking
claim_tickets()
for update skip locked
Ticket pool
postgres · 24 rows
A
A
B
B
C
19 / 24 available
6 events · play, or hover a node to trace its path
Concurrent transactions skip locked rows — no duplicates, no race conditions.
03

Payment Integrity

The checkout flow was designed around a single principle: no user should ever be left in an ambiguous state. A failed payment should never result in allocated tickets lingering in limbo, and a successful payment should never leave a user without their ticket numbers.

The system achieves this through a staged transaction model:

  1. 01

    Pre-allocation

    Tickets are reserved from the pool and an order is created in a pending state before the user enters payment details.

  2. 02

    Payment processing

    Stripe handles the transaction with full PCI compliance.

  3. 03

    Confirmation

    On successful payment, the order is marked complete, tickets are activated, and a confirmation email is dispatched.

  4. 04

    Rollback

    On failure, the pending order is cancelled and tickets are released back into the available pool automatically.

This guarantees the ticket pool remains consistent at all times, regardless of what happens during checkout.

No user is ever charged without tickets — no tickets are ever stranded without payment.

Fig.Payment with rollback
SuccessFailure
Step 1
Pre-allocate
reserve tickets, order pending
Step 2
Payment intent
card charged once
Confirm
order complete, tickets live
Rollback
order cancelled, tickets released
Pool consistent
none sold twice, none lost
6 events · play, or hover a node to trace its path
Tickets are reserved before the charge and released if it fails — the pool can't drift.
04

Regulatory Compliance

UK Gambling Commission regulations require prize competitions to include a skill element to distinguish them from lotteries. This isn't optional — it's a legal requirement.

The platform enforces this at the API level. Each competition can be configured with a skill-based question that participants must answer correctly before they can proceed to checkout. The validation happens server-side — a user cannot create a payment intent without a verified answer on record.

All answers are stored and auditable, giving the operator a clear compliance trail without adding noticeable friction to the purchase flow.

Compliance enforced at the API level — not through policy documents.

05

Automated Communications

Customer communication spans the full competition lifecycle, handled by six email templates built as React components and rendered server-side:

Ticket confirmations

Sent immediately after purchase

Draw reminders

Triggered 24–48 hours before a draw date

Winner announcements

Sent to the winner with next-step details

Welcome emails

On account creation

Postal entry confirmations

For free postal entries (UK regulatory requirement)

Non-winner notifications

Sent to all entrants after a draw — closes the loop and encourages re-entry

The draw reminder system runs as a Deno-based edge function on a cron schedule, identifying upcoming competitions, grouping ticket holders by user, and dispatching personalised emails.

Fig.Entrant email lifecycle
MomentEmailFree route
Sign-up
Welcome
Purchase
Ticket confirmation
Draw −24h
cron
Draw reminder
Draw
Winner
announcement
Non-winners
notice
Free route
Postal entry
by hand · same draw
6 events · play, or hover a node to trace its path
Six templates, each fired automatically by the moment in the entrant's journey that needs it.
04Architecture
Decisions04

Architecture.

Frontend
Next.js 16 / React 19 / TypeScript / Tailwind CSS / Radix UI
Backend
Next.js API Routes / React Server Components
Database
Supabase (PostgreSQL + pgcrypto + Row-Level Security)
Auth
Supabase Auth (JWT-based)
Payments
Stripe Payment Elements + Webhooks
Email
Resend API + React Email

Key Architecture Decisions

The winner selection function runs as a PostgreSQL stored procedure using pgcrypto. The cryptographic operations happen at the database level, inside a transaction, with no exposure to the application layer. Even if the API were compromised, the draw logic and its randomness source remain untouched.

05Key features
Features12

Key features.

01

Provably fair draws

SHA-256 cryptographic proof with public verification endpoint

02

Concurrent ticket sales

Atomic allocation with row-level locking under load

03

Transactional payments

Pre-allocate → pay → confirm/rollback cycle via Stripe

04

Regulatory compliance

Skill question enforcement at API level

05

Multi-competition support

Parallel competitions with independent ticket pools and draw dates

06

Real-time progress tracking

Live sales stats via PostgreSQL materialized views

07

Admin dashboard

Competition management, one-click draws, winner management, CSV exports

08

Multi-item cart

Purchase tickets across competitions in a single Stripe checkout

09

Automated email lifecycle

Six templates covering the full competition lifecycle — purchase to draw result

10

CDN-backed media

Image uploads via Supabase Storage with edge delivery

11

Mobile-first UI

Responsive design built with Radix UI primitives and Tailwind CSS

12

Database-level security

Row-level security policies enforced on every table

    • 01Provably fair drawsSHA-256 cryptographic proof with public verification endpoint
    • 02Concurrent ticket salesAtomic allocation with row-level locking under load
    • 03Transactional paymentsPre-allocate → pay → confirm/rollback cycle via Stripe
    • 04Regulatory complianceSkill question enforcement at API level
    • 05Multi-competition supportParallel competitions with independent ticket pools and draw dates
    • 06Real-time progress trackingLive sales stats via PostgreSQL materialized views
    • 07Admin dashboardCompetition management, one-click draws, winner management, CSV exports
    • 08Multi-item cartPurchase tickets across competitions in a single Stripe checkout
    • 09Automated email lifecycleSix templates covering the full competition lifecycle — purchase to draw result
    • 10CDN-backed mediaImage uploads via Supabase Storage with edge delivery
    • 11Mobile-first UIResponsive design built with Radix UI primitives and Tailwind CSS
    • 12Database-level securityRow-level security policies enforced on every table
06Next project
Next04 / 05

Looking for a platform built on trust?

Whether you need cryptographic security, high-concurrency systems, or regulatory compliance built in from day one — we'd love to talk.