I am working on an shopping website in which we only have unique products. So users can see and add same products to their cart simultaneously but when they will place an order then whosoever will place it first will get the same items added to cart.
But I have problem that how will I ensure that my place order code when called will be locked and all other requests have to wait in queue until its not complete. I read about lock keyword but not much idea. Any help will be appreciated.
Below are few steps for my code:
Step 1: To call a 3rd party service to see that item is available or not Step 2: If Item is available then buy it by calling that 3rd party service. Step 3: If bought successfully then update the database with flags etc.
lock's are for. You need a way to 'remove' an item from inventory temporarily while it is in a persons cart (if I understand your question correctly). The best way I can think is by having the cart in the database. then you can always query against the carts to see what your potential stock is.