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
Software Engineering Fundamentals
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

0

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
optimistic concurrency
ETags
HTTP conditional requests
lost update
API design
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. 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 Problems
Sample Answer
Requirements
  • GET returns the body and an ETag header for its current version.
  • PUT or PATCH with If-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...


Submit Your Answer
Markdown supported