.NET Architecture & System Design Interview Question #74
What is optimistic concurrency control?
Database Scaling, Partitioning, NoSQL & Data Consistency Mid-Level Intermediate
Quick Interview Answer
Optimistic concurrency control assumes conflicts are relatively uncommon. A record carries a version or concurrency token, and an update succeeds only if the version has not changed since it was read.
Detailed Explanation
Optimistic concurrency control assumes conflicts are relatively uncommon. A record carries a version or concurrency token, and an update succeeds only if the version has not changed since it was read.
If another writer changed the record first, the update detects a conflict and the application can retry, merge, or ask the user to resolve it. EF Core supports concurrency tokens such as SQL Server rowversion.
Code Example
UPDATE Orders
SET Status = @status
WHERE Id = @id
AND Version = @originalVersion;
0 rows updated -> concurrency conflict