ASP.NET Core Web API Interview Question #186
How should concurrency conflicts be handled in a REST API?
Senior API Design, Architecture, Scalability & Production Scenarios Senior Advanced
Quick Interview Answer
Use optimistic concurrency when multiple clients may edit the same resource. A version token, rowversion, or ETag can represent the state the client originally read.
Detailed Explanation
Use optimistic concurrency when multiple clients may edit the same resource. A version token, rowversion, or ETag can represent the state the client originally read.
If the resource changed before the update, reject the stale write with a documented conflict or precondition response and let the client reload, merge, or retry according to business rules.
Code Example
PUT /api/products/10
If-Match: "v7"
// If current version is no longer v7,
// reject the stale update instead of overwriting it.