Update multiple records using web api

Today in interview I got asked this kind of question.

Let’s say you want to update multiple records same time using web api then how you can do that.

As it is around 1000s of records for updating..

So I give reply to use async and await for now.

Then he ask me if user 1 update record and same time user 2 update record so which will take action and how this scenario can handle.

So what should be best reply for this kind of question.

Answer

Question: If user 1 update record and same time user 2 update record so which will take action and how this scenario can handle?

Its call "concurrency", To handle this kind so scneario you have to use locking mechanism
for handling concurrency (updating same record from different user) so that user may understand that other
user is modifying this as well.

Asp.net Entity Framework Aspect:

In asp.net Entity framework has
RowVersion property which will track update log for a specific data
when it’s been updated.

Two kind of Concurrency Mechanism you can use:

You can have a look official document
for more details. Additionally here is the implementations

Database Aspect:

From database you can also handle this scenario. All the database also
has Locking mechanism to work on same records simultaneously by
multipole user. You can have a look here

Hope it will guide you accordingly and redeem your confusion.