I think Martin Fowlers description of optimistic and pessimistic locking is excellent. So excellent that I had to share…

“Let’s suppose that Martin and David both want to edit the Customer file at the same time. With optimistic locking both of them can make a copy of the file and edit it freely. If David is the first to finish, he can check in his work without trouble. The concurrency control kicks in when Martin tries to commit his changes. At this point the source code control system detects a conflict between Martin’s changes and David’s changes. Martin’s commit is rejected and it’s up to him to figure out how to deal with the situation. With pessimistic locking whoever checks out the file first prevents anyone else from editing it. So if Martin is first to check out, David can’t work with the file until Martin is finished with it and commits his changes.” - Martin Fowler : PoEAA

SVN of course uses optimistic locking and Microsoft Visual Source Safe uses pessimistic locking. I’ve become a huge fan of SVN recently, and since we started using it here at work, I feel like I’ve become more productive. Gone are the days when I would hear

** “Can you check in the project, I need to add a file.” **, ** “Where’s <enter name>? He’s not in today? But he’s got a file checked out that I need.” **

Patterns of Enterprise Application Architecture by Martin Fowler Read more about this title…

comments powered by Disqus