A retailer's single-use coupon is redeemed many times when an authenticated user sends parallel redemption requests. Each request passes the "unused" check before any request marks the coupon used. What is the best fix?
Show the answer
Correct answerA. Lock the coupon row across the check and the redemption
AWhy this is right: Holding a lock across check and update lets only one request through at a time, so the coupon can be redeemed once.
BWhy not this: Format validation checks the code's shape; a valid code can still be redeemed repeatedly in parallel.
CWhy not this: Rate limiting reduces request volume but does not stop two concurrent requests from both passing the check.
DWhy not this: A CSRF token proves the request came from the user's own form; the user here is the one sending the parallel requests.
The flaw is a race condition: the check and the update are separate steps, so concurrent requests all pass the check. Mutual exclusion (a row lock held across both steps) serializes them. Rate limiting only slows requests and does not make the check-and-update exclusive.