There exists two types of synchronisation techniques to make sure you avoid concurrency issues and race conditions when updating database records. These are as follows.
- Optimistic locking
- Pessimistic locking
Optimistic locking is usually performed by using native database mechanism such as RowVersion in SQL Server, TimeStamp in MySQL, or ETag in Cosmos DB. These are special field types that changes automatically as the record is updated, allowing you to inject the values of these fields as a criteria to your update invocations. For an example of how this works, imagine the following schema.