The Lost Update Problem - Part 3 : Applied Prevention
I discussed the problem of lost updates in the two previous posts:
- The lost Update Problem in the Context of Transactions, and
- Preventing Lost Updates in Web Applications.
This post demonstrates how to prevent lost updates within a Ruby on Rails web application. The focus of this post is practical, in the sense of getting the job done with a minimal understanding of the concepts. The two previous posts contain all the background information. The main part of this post is a screencast. It shows the complete process of hacking out the demonstration, and it features also two distinct ways to prevent lost updates. The links to the code, as given in the last section, provide a concise access to the relevant content.
- 0:00 Set-Up
- 4:00 Lost Update - Demonstration
- 7:00 Prevention from the Application Layer
- 23:30 Prevention from the DB Layer
The demonstration of the problem itself is featured in the lostupdate branch. The code as generated by the accounts scaffold is unmodified.
Finally, the storedproc branch, tackles the problem from within the database using triggers and stored procedures. The code for those is contained in the corresponding migration. There is some support from the application layer which is located in the update action of the accounts controller.