Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Open Points: 125 Time: 01:45 - Jul 05, 2007  

viduvidyas

how to solve the concurrency problem in asp.net

for example if u consider the reservation of tickets... if two persons (A,B) are going to book a ticket at the same time and only one ticket is available,who will get the ticket and how the concurrency problem is maintained

Categories

Answer Discussion
Tutorials

 

rcastagna

Date:: Nov 17, 2009

Time:: 18:42

Good question...I guess the simplest answer is: whoever gets their order in first gets the ticket.

Given the very remote chance that the two users would click the "buy now" button and the very same millisecond utilizing a timestamp for the button click could be the way to solve the "tie" betwen the two.

Let's look at how this could flow...

Assumption #1: All ticket inventories are being held in a database.
Assumption #2: Multiple users can view all tickets available until a ticket has been purchased and is removed from the available inventory count.
Assumption #3: A ticket can only be purchased once and only by a single user.

User A is looking at a ticket for Row A, Seat 1. User B is looking at the same ticket. Both of them decide to purchase Row A, Seat 1.

Once they've clicked the "Buy Now" button, both users are potentially buying the same seat, a clear violation of Assumption #3. Now it's a race to see who can complete the transaction first.

This is where maintaining timestamps comes into play, as well as transactions when dealing with your database.

For the sake of argument, let's say User A clicked the button at 12:00:00:123 and User B clicked the button at 12:00:00:456...it's easy to say that User A wins and gets the ticket. But, User A has not technically completed the purchase - they haven't paid for the ticket.

User B is a bit more on the ball, and even though he clicked the button later than User A to start the process, he has paid for the ticket at 12:00:01:000 and User B completes the payment at 12:00:01:875 which means that User B is the winner and has claim to the ticket.

At this point, you will need to "rollback" User A's purchase, including refunding the money and presenting them with an error message stating the ticket has been purchased.

User B will be presented with the appropriate receipts and confirmation messages to indicate the successful purchase of the ticket.

Yes, it's a lot of comparison within your business logic, but it also prevents a couple of issues: 1) Locking issues at the database can be problematic and actually freeze a system rendering it useless, and 2) it prevents User A from "squatting" on a ticket preventing other interested parties from purchasing it.

I know this is a complex issue you're dealing with, so feel free to follow up here or you can look me up on the web at http://www.castagna.net.

rcastagna

Date:: Nov 17, 2009

Time:: 18:46

Aw, rats...didn't proofread my answer close enough...

Restating the paragraph that starts with "User B is a bit more on the ball...":

"User B is a bit more on the ball, and even though he clicked the button later than User A to start the process, he has paid for the ticket at 12:00:01:000 and User *A* completes the payment at 12:00:01:875 which means that User B is the winner and has claim to the ticket.

As stated correctly, User B is successful in the purchase while User A has the transaction "rolled back" as a result of the unsuccessful purchase attempt.

Sorry for the confusion...

admin

Date:: Dec 15, 2009

Time:: 10:40

The question looks to be abandoned by the user who asked it. If no action is taken within 2 days, a Quomon Moderator will consider closing the question and distributing the points.

The Quomon Team

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Tutorials cannot be submitted until the Answer Discussion is complete.

Submit answers in the Answer Discussion area

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10354

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es