What is a practical real world example where a Redis transaction ensures data consistency across multiple related keys?
Short answer
A ticket booking system can use a transaction to simultaneously decrement the available seat count and add the buyer's reservation record, ensuring that both changes are applied together so the seat count never gets out of sync with the actual list of reservations, even under…
Advertisement
AModel answer
A ticket booking system can use a transaction to simultaneously decrement the available seat count and add the buyer's reservation record, ensuring that both changes are applied together so the seat count never gets out of sync with the actual list of reservations, even under high concurrent booking load.
Example
MULTI DECR event:5000:available_seats SADD event:5000:reservations 'user789' EXEC
Real-world example
An online ticketing platform relies on a Redis transaction during checkout to atomically reduce the seat count and record the new reservation, preventing overselling even when many users are booking seats for the same popular event at once.
Likely follow-ups
- What happens if the available seat count would go negative as a result of this transaction?
- Should this be combined with WATCH to prevent overselling under heavy concurrency?
Related topics