VinothNair
VinothNair

Reputation: 634

How to make sure that a unique record is returned to each concurrent request from a asp.net controller action method

In one of our ASP.Net application we have to assign customer complaints to support executives. Customer complaints are storied in a database table. We use entity framework code first approach.

When the support executive logged in to the system he will be provided with the customer complaint (view) with one of the complaint assigned to him. Once he completes the formalities for the complaint and submit the information, he will get the next complaint assigned to him and he will continue the same till end of the day.

The challenge here is there are N number of support executives working concurrently and the same action method (AssignCustomerComplaint) is triggered at the same time. Now how will we make sure that each customer executive will get unique complaint that are not assigned.

Note : I already have a field in the database table to say whether the complaint is assigned to a support executive or not (storing the userid of the support executive). So in the business logic I am checking whether the complaint is assigned and if not then I am updating the userid field with the current user and then returning the view with the model. But in some scenario because of the concurrent requests, same complaint is returned to different support executives (the latest request again updates the userid field). It’s obvious that there is no lock applied to that record.

I can lock the controller action method till we assign a particular complaint to a support executive but wanted to check is there any better way of doing this without affecting the performance.

Upvotes: 0

Views: 49

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239250

I would handle the assignment out of sync, since that's the only part that will have concurrency issues. If two complaints are logged at the same time and you simply retrieve the next rep to assign, there's the potential that both will be assigned to the same rep, instead of two different reps.

However, if you simply save the complaint and then schedule a background process to go back and assign unassigned complaints to reps in order, then you effectively remove the concurrency issues from the equation.

Upvotes: 0

Related Questions