Jump to content
Larry Ullman's Book Forums

No Need For Table Locks?


Recommended Posts

I bought an OReily book about 8 years ago which had an example on how to create an ecommerce website. One feature they covered was table locking when ordering items and completing the purchase. Today I saw your book at Barnes & Noble and gave it a quick look. Is there a good reason why this isn't covered in the book?

 

Also, how are orders covered if there is a single item of a product remaining in which two customers wish to purchase that last item?

 

I'd like to purchase this book since I have an ecommerce website to build from scratch later on in the year, but would like to get some worries ironed out first.

 

Thanks!

b

Link to comment
Share on other sites

This is a subject that I am also interested to hear. I have also seen this mentioned in an oreilly book, the author said if you are worried about two users accessing the same row of a table then you should lock the tables. He also mentioned that this method would slow down the website performance substantially. I have three books on Ecommerce development and none of them lock tables, but as I said on one of my previous posts Larry Ullman has the best book on the market. You will find with orielly books that one author tends to rub off another, whereas Larry has his own uniqueness in ease of expression, his books are just laid out more logically and easy to follow. The other thing I want to comment on is that u can't expect one book to cover everything you need especially in the world of eccomerce today, these books are merely starting points.

 

Okay I think I have rambled on enough for one day. Let's wait for the answer.

Link to comment
Share on other sites

Well, I'll start by saying that there are often multiple ways of doing things and some aren't necessarily better than others. But in this particular case, table locking in MySQL has improved dramatically in the past 8 years. And different table types perform automatic locking on the table or row level. So I generally don't think it's something you need to worry about unless you have an extremely high demand site, in which case the automatic locking may adversely impact the performance.

 

As for how orders are handled if two people buy the same thing, that's something I specifically discuss in the book. In the book, I err on the side of not selling things that may not be in stock, and items are taken out of stock once the sale goes through, which is a middle ground over taking them out of stock once the items are in a cart (which has the possibility that the user never completes the sale). So I talk about this, and demonstrate the one approach, and discuss how you need to determine what's appropriate for your site. For example, if the stock is hard to come by, then you need to be extra careful. If it's easy to get more stock, then you can be more casual about it, thereby maximizing sales. Good questions!

  • Upvote 1
Link to comment
Share on other sites

Thanks for the reply Larry. Since this site shouldn't have too much traffic, I think I'll steer clear of table locks. The ORielly book never really explained the disadvantages of using locks, only why they should be used for concurrency. I'm looking forward to reading your book.

 

b

Link to comment
Share on other sites

 Share

×
×
  • Create New...