Marnen Laibow-Koser wrote:
> Cathal O'Riordan wrote:
> [...]
>> My concern is that my code won't guard against a race condition where
>> 2 or more users try to register for a course that is near it capacity
>> limit. My first thought was to wrap the registration code in a
>> transaction and rollback if the capacity of registrations on a course
>> has been exceeded.
> [...]
> 
> Use check constraints in the DB and let *it*, not your app, worry about 
> concurrency issues!

That's one approach. Wrapping it up in a transaction with read isolation 
would work fine too. Alternatively (and better for concurrency), keep a 
counter cache on the registration_count and use the default isolation 
level.

--
Roderick van Domburg
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to