Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have one api.. that is been called by multiple applications through azure logic apps. There is one scenario..The applications which are calling api sometime process concurrently due to which some dirty read happens in api business logic. The request should be processed sequentially, but here in this case(concurrent calls) giving issue. Is there any solution to handle this.

Note : we can implement Azure service bus but for now, we don't want to use that because multiple applications are calling api, so they need to change on their end too.. is there any solution that we can handle only on our end.(API Level) Any suggestions.

Please respond..Thanks :-)

Azure,Asp.Net core

What I have tried:

Throttling will not solve this as there will no. of requests. It will slow down.
Posted
Updated 6-Dec-20 13:37pm
v3
Comments
[no name] 2-Dec-20 12:12pm    
Then use pessimistic locking. Or are you looking for a "no code" solution. (They don't exist).

1 solution

You state there are dirty reads in your business logic - which sounds strange. But as you have tagged your question "SQL" then make sure you have the correct isolation level set. Committed reads is the default but you can ensure it is on with
SQL
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
at the head of your query.

By the way, SQL is normally very good at handling concurrency so the problem is most likely to be in the way you have implemented your API.

You could consider queuing the requests into your API - this would be invisible to your callers, but may result in a performance hit (unless you have many listeners in place - back to square 1) - have a look at Amazon Web Services Simple Queue Service Using the Java 2 Software Development Kit[^] or Message Queue[^]. IBM also have a good offering but we're starting to talk some serious money now.

As to your comment about throttling slowing things down - that is what it is meant to do! However, your requirement
Quote:
The request should be processed sequentially,
will have the same effect
 
Share this answer
 
Comments
Prasad Nikumbh 6-Dec-20 19:38pm    
I am using Entity Framework.I dont want to use any Message queue for now.
CHill60 7-Dec-20 5:03am    
What has using Entity Framework got to do with not using a queue? They are not mutually exclusive! If you had a personal preference not to use queuing then perhaps you should have mentioned that in your post.
CHill60 7-Dec-20 5:53am    
Nope - you said you didn't want to use Azure service bus because other applications would need to change. I am not suggesting that you make the calling applications change. I'm afraid I don't know what you mean by a "mediator".
You also didn't mention that you wanted a temporary solution. Queuing can be handled entirely at the API end - invisible to the calling applications.
Or you can try pessimistic locking as already suggested by @Gerry-Schmitz. There is no magic wand here!
Try some other Research on EF concurrency[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900