Workshop index · Download all examples and lessons
The transport can accept a booking and then lose its response. Retrying with the same key reaches a store that ignores that key and reserves twice. With capacity 5 and a two-seat booking, the candidate accepts two entries and reports remaining 1. The contract requires one entry and the original response, remaining 3.
Cache the successful result by request key at the same boundary as the reservation. This in-memory reference handles sequential Python calls and interleaved TypeScript calls in one event loop. It is not a distributed transaction or a durable idempotency store.
The TypeScript candidate also reads availability before an await. Two requests can both observe 2, both accept 2 seats, and both write remaining 0. Checking only that remaining is non-negative misses the overbooking; total accepted seats is 4. The fix keeps the availability check, mutation, and request-key result recording together without an intervening await.
In a real database-backed service, this invariant needs a transaction, a suitable atomic conditional update, or another storage-level concurrency control. Moving JavaScript statements alone would not protect multiple workers or processes. Those production concerns are outside the simulated store’s scope.