Ask YC: How do you handle locking in your app?
At 1:00, Jane pulls a record into her browser: Lakeside High School, 123 Main St., 555-1111.
At 1:05, Fred pulls the same record into his browser.
At 1:06, Fred changes the address to 123 Oak St.
At 1:08, Mary changes the phone number to 555-2222.
Questions:
How to you handle the database locking?
- Pessimistic, lock the row at 1:00 and don't let Fred have it?
- Optimistic, let everyone take anything they want, but don't let Mary update?
- Column level locking?
- Special processing in you app?
How do you maintain state?
- Using sessions?
- Keeping a "before image" of the row? In the client? On the server? As a separate data base record?
I realize there is not one correct answer. Just curious how other YC'ers handle situations like this.