How would you protect the database during a popular ticket sale without trusting Redis for correctness?
After this you can answer: How would you protect the database during a popular ticket sale without trusting Redis for correctness?
Say it in 30 seconds
Section titled “Say it in 30 seconds”The deeper answer
Section titled “The deeper answer”The gate identifies an intent using the user and idempotency key and gives a reservation an owner token. Missing inventory is initialized from Postgres. A sold-out gate decision still checks for a committed idempotent replay, so a retry can recover a booking that consumed the last seat.
After the database outcome, a newly taken reservation is settled. Failed or replayed work refunds that debit where appropriate. A crash can leave drift, so reconciliation snapshots Redis before reading Postgres and conditionally applies a repair only if the Redis state has not advanced. Live debits are subtracted conservatively, which can temporarily reject demand rather than risk overstating supply.
This reduces hot-row contention but is not a complete waiting room or fairness policy. The current design still does database reads on some rejection paths. A real sale would need explicit admission targets, load tests, customer messaging and a plan for protecting the database when the advisory gate is unavailable.
Counter-questions
Section titled “Counter-questions”Can Redis accidentally let too many requests through?
Can Redis reject a customer when seats remain?
Does failing open guarantee bookings during a Redis outage?
Where in MiniTickets
Section titled “Where in MiniTickets”Read Rate limits inventory gate, then inspect the inventory-gate piece →.
apps/api/src/services/booking-inventory.ts → createGatedBookingRead this book online: https://book.theversehub.in/