Home > Blockchain >  Concurrent request handling in ASP.NET web api
Concurrent request handling in ASP.NET web api

Time:05-23

I have a very simple web application that contains a few endpoints in it (Get, Put, Delete).

The task of the app is to store/return/remove some data from my DB.

I want to add concurrency to the project to avoid cases when the app receives a few requests at the same and handles it in parallel.

Can you please provide me with some simple solution/manual how to implement it?

Thank you!

UPD:

Just to provide an example:

if I send two requests (with Postman), for instance, DELETE and GET it executes it in parallel, so I receive incorrect result.

I want to finish the first (DELETE) and only after that start the second

CodePudding user response:

Usually, web applications handle requests concurrently in order to increase the number of users that they can serve. So concurrency is central to a web application and for most cases this does not lead to a problem. Also the underlying databases are usually able to handle parallel requests very well.

Of course, from a developer's perspective you can construct cases where two requests arrive exactly at the same point in time, one deleting data and the other reading data. For most web applications it is more important to handle more users, therefore they accept that in this theoretical case they return data in a response that just has been deleted.

Also, it might seem easy to handle requests sequentially in a single-server environment, but it will be hard in a multi-server deployment. Also, it leads to a degradation of application performance if a request has to wait until others have finished.

So unless your scenario is very specific or you encounter problems due to concurrent requests, I'd propose to stick with the default behavior.

CodePudding user response:

Not quite sure what you are asking for when you want concurrency and at the same time not letting it handle parallel requests?

I'll give it a try anyway:

Given its a dotnet core project. As long as you use async operations against your db and makes sures its async all the way to the endpoint, you should be able to handle concurrent requests just fine.

  • Related