How a Unique DB Constraint Prevents Double-Selling Seats at Scale
A software engineer who built booking systems for events hosting up to 20,000 spectators has shared the architecture behind reliable seat reservation at high concurrency. The core problem is the 'lost update' — two users passing an availability check simultaneously, both being assigned the same seat. The solution separates clicking from selling: a click creates a short-lived hold stored in Redis via an atomic Lua script, while only a completed checkout writes to the database. Redis handles the high-churn, expiring holds without polluting the primary database, but the true guarantee is a PostgreSQL UNIQUE constraint on the event and seat combination. A reference implementation with a 200-concurrent-request stress test has been published on GitHub to demonstrate the approach.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in