0

I have an enterprise application with multi users, It is logistics imports and exports system, we publish invoice per clearance Number. Our problem is tow users publish invoices with same clearance in real time for example 3 sec. We use N Layer Architecture Asp .NET MVC and Entity framework, what is the best practice for this problem?Is it way to lock section By my clearance Number?

bahar.alirezaei
  • 87
  • 3
  • 11

1 Answers1

0

To manage concurrency there are two ways

  1. Optimistic locking
  2. Pessimistic locking

See the link Optimistic vs. Pessimistic locking
Optimistic Locking is a strategy where you read a record, take note of a version number (other methods to do this involve dates, timestamps or checksums/hashes) and check that the version hasn't changed before you write the record back. When you write the record back you filter the update on the version to make sure it's atomic. (i.e. hasn't been updated between when you check the version and write the record to the disk) and update the version in one hit.

Pessimistic Locking is when you lock the record for your exclusive use until you have finished with it.

I have used Pessimistic locking with SignalR to provide a realtime notification to users.Whenever user edits a record we will add a record with unique identifier of that record in a database table(here as the data is volatile we used nosql redis to store the lock data).When another user tries to edit the same record will show a notification saying the record is locked by the user name.When the other user completes the edit will send a notification the user completed the updation.

Krishjs
  • 358
  • 2
  • 17
  • I don't have any record to lock this.It is a new record.I search for a solution on the web platform.I know row version check on update mode.it doesn't solve my problem. – bahar.alirezaei Dec 20 '17 at 12:01
  • Whenever user enters a clearance number just add a record in database with that clearance number so that if another user selects the same number just show a message another user is creating invoice. – Krishjs Dec 20 '17 at 15:40