Redemption integrity
- Atomic prize allocation
- A redemption and the prize it wins are written in one database transaction. The prize row is locked before it is assigned, so the last prize can only ever be won once.
- Single-use codes
-
Each code is locked for the duration of its redemption and a unique constraint sits behind the lock. A
second request for the same code gets
CODE_ALREADY_REDEEMEDwith the original time. - Idempotent requests
-
Send an
Idempotency-Keyand a retried request returns the stored response instead of running again. The same key with a different body is refused. - Concurrent redemption protection
- Simultaneous requests queue on the code, then on the participant's limit, then on the prize, always in that order, so they cannot deadlock. A request that waits too long is told to retry rather than left hanging.