Re:Race conditions on Facebook, DigitalOcean and others (fixed)
by some1else on Monday April 27, 2015 @06:03AM
(#9445280)
A simple Discount domain model with validations:
Limiting down to a single Promo-code per order:
[ Parent
| on HN ]
Re:Race conditions on Facebook, DigitalOcean and others (fixed)
by gavingmiller on Monday April 27, 2015 @09:57AM
(#9446281)
This right here is the heart of race condition bugs, and is NOT race condition safe. When running multiple web servers and without a "validates_uniqueness_of" constraint on your database, multiple requests hitting multiple different web servers can claim multiple discounts for the same user. Problem only grows as your number of web servers grow!
Re:Race conditions on Facebook, DigitalOcean and others (fixed)
by kawsper on Monday April 27, 2015 @02:24PM
(#9448199)
Read the part "Concurrency and integrity" in the Rails documentation: http://apidock.com/rails/ActiveRecord/Validations/ClassMetho...
You need to enforce the uniqueness in the DB.