Prevent Lost Updates in a Document API Using ETags
Last updated: November 29, 2026
Quick Overview
Two clients read the same document, both edit it, and both save. Design and implement the update contract for a REST resource so the second save does not silently overwrite the first, using ETags with If-Match and If-None-Match.
Microsoft
November 29, 20260
0
0 solved
Two clients read the same document, both edit it, and both save. Design and implement the update contract for a REST resource so the second save does not silently overwrite the first, using ETags with If-Match and If-None-Match.
Microsoft Graph, SharePoint and Azure Resource Manager all rely on ETags for optimistic concurrency, so this is a realistic screen for API and backend roles. The interviewer looks for the lost update problem, correct HTTP status codes, an atomic compare-and-write on the server, and a client retry strategy.
What the Interviewer Expects
- Explains the lost update problem with a concrete interleaving
- Returns an ETag on reads and requires If-Match on writes
- Returns 412 Precondition Failed on mismatch and 428 when the header is missing for risky writes
- Performs the version check and write atomically
- Supports conditional GET with 304 and create-only with If-None-Match: *
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How should a client recover from a 412?
- When would you choose pessimistic locking (check-out) instead?
- How would you implement this on top of a database row?
- Strong versus weak ETags: when does the difference matter?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
GETreturns the body and anETagheader for its current version.PUTorPATCHwithIf-Match: <etag>succeeds only if the resource is still at that version; otherwise `412 Precondition Fa...
High-Level Design
The lost update: Alice and Bob both GET version 1. Alice saves a new title (version 2). Bob saves a new owner based on version 1, overwriting Alice's title. With ETags, Bob's save carries `If-Matc...