Hi, I am currently developing a website for selling tickets for events. A big issue here is concurrency. Multiple user should not be able to buy tickets at the exact same time and create a inconsistent database where more tickets have been sold than what was actually available.
The act of purchasing is a two step process: 1. Check that there are enough available tickets left. 2. Create ticket records representing the users tickets. This is a critical part of the system and mutual exclusion must occur. At the moment, I have created a file based semaphore. Here is an isolated example of how I do this. The example shows mutual exclusion on a per-event basis, enabling multiple purchases to occur at the same time, as long as they are for seperate events. https://gist.github.com/4366276 This works swimmingly. (And it's so cool!) But I would much rather like to utilize database transactions with an isolation level of serializable. I understand that ActiveRecord::Base#save already [creates a transaction](https://github.com/rails/rails/blob/master/activerecord/lib/active_record/transactions.rb#L257). To my knowledge, there's nothing in Rails resembling the possibility to set the isolation level of an transaction. I think that is an issue. Isolation level is, in my opinion, a huge part of what transactions are. At least I could use a feature like that, in my case. It would be so awesome if one for instance could do transaction.save :isolation => :serializable or transaction :isolation => :serializable do > # … > end What do you think? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/5WfQkkKQWvsJ. 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-core?hl=en.
