HTTP ETags and Lost Updates: What If-Match Protects and What It Does Not
HTTP AND API RELIABILITY
A version tag can support stale-write rejection. It does not acquire a lock, merge two edits or turn several business operations into one transaction.
By Hossam
Two editors can both save successfully and still lose an edit
A client downloads a settings document, changes one field and sends the entire document back. While it was editing, another client changed a different field. If both uploads are accepted without checking the version they started from, the later upload can erase the earlier change even though both clients receive success responses.
That is the lost-update problem addressed here. It is different from asking whether one request was delivered twice. A service can avoid duplicate execution and still accept an obsolete replacement document. Conversely, a conditional write can reject stale state without supplying a complete recovery policy for an unknown request outcome.
This guide explains documented HTTP semantics, then uses a fictional two-editor sequence to make the boundary concrete. No server, framework, proxy or cloud account was tested. The implementation guidance is engineering analysis, not a claim that adding one header repairs an existing application.
Documentation: HTTP Semantics, RFC 9110, MDN conditional requests guide.
An ETag describes a representation, not a reservation
RFC 9110 defines an entity tag as an opaque validator for the selected representation. Treat the returned quoted value as a token supplied by the server. Do not assume it is a database row number, a content hash you can reproduce or a globally unique identifier shared across resources.
A strong validator must change when the representation data changes in a way observable in a successful GET response. The standard also discusses content negotiation: differently encoded representations can need different strong tags. This matters when a client reads through one representation path and writes through another. The API must define a usable relationship between those operations.
Simply returning ETag on a GET does not prevent a later unconditional overwrite. The client must submit an appropriate condition, and the receiving service must implement its semantics. The tag does not stop another client from writing while the first client is editing.
Documentation: HTTP Semantics, RFC 9110, MDN ETag reference.
If-Match asks the server to reject an obsolete basis
For an update based on a fetched document, the usual pattern is to send its entity tag in If-Match. The origin server compares the supplied tag with the selected representation using strong comparison before applying the method. A list of tags means that any matching member can satisfy the condition; it is not a demand that every tag match.
In the ordinary stale-write case, a failed condition produces 412 Precondition Failed and the requested mutation is not performed. Preserve that distinction: the server has rejected the condition, not merged the payload or validated that the proposed new business state is sensible.
RFC 9110 includes an important qualification that short summaries sometimes omit. A server may return a successful response to a state-changing request whose condition failed when the requested change appears to have already been applied. The standard discusses risks for similar but uncoordinated operations. Do not turn the normal 412 case into an assertion that every failed If-Match must always produce exactly that response.
Documentation: HTTP Semantics, RFC 9110, MDN If-Match reference.
A fictional sequence: preserve the other editor's change
Assume an invented document initially contains a title of Draft and a visibility value of private. Both editors receive the same strong tag, called rev-a here solely for illustration. Editor A changes the title to Reviewed and saves with that tag. The service accepts the conditional replacement and returns the new representation with a new tag, rev-b.
Editor B still holds the old document and changes visibility to shared. Its replacement payload still contains the old title Draft. If the service accepts that unconditional payload, A's title change can disappear. If the replacement instead carries the original tag in If-Match, the normal documented result is rejection because rev-a is no longer current.
After that rejection, B should fetch the current document and preserve the user's pending intent while deciding what to apply again. A suitable application might show both versions or reapply an independent field change after validation. Blindly attaching rev-b to the unchanged obsolete payload would remove the protection and overwrite Reviewed with Draft.
These labels and fields are fictional, not server responses captured during an experiment. The example assumes the service correctly implements conditional replacement and that the changed fields are covered by its representation validator. It does not establish the behavior of any particular API.
Documentation: HTTP Semantics, RFC 9110, MDN conditional requests guide.
Weak tags and wildcards answer different questions
A weak tag has the W/ prefix. Strong comparison requires both tags to be non-weak and their opaque values to match character for character. A weak tag therefore cannot satisfy a listed If-Match validator just because its visible text resembles the current tag. Do not remove W/ and pretend the server issued a strong validator.
If-Match with an asterisk has different semantics from supplying the version that was read. It asks whether the origin has a current representation of the target resource. It can stop an update when the resource does not exist, but it does not distinguish the old representation from a newer one. Existence is weaker than unchanged-since-my-read.
For a create-only operation, If-None-Match with an asterisk expresses the opposite existence condition. It can prevent an unsafe method from replacing a representation that already exists. A separate existence lookup followed by an unconditional create leaves a race between those operations and is not a substitute for the conditional request.
Documentation: HTTP Semantics, RFC 9110, MDN If-Match reference, MDN conditional requests guide.
A 428 policy is not automatic protection for every writer
RFC 6585 defines 428 Precondition Required for an origin server that requires a conditional request. That is different from 412: one says the required precondition was not supplied under the service's policy, while the other says a supplied condition evaluated false. Responses using 428 should explain how to resubmit successfully and must not be stored by a cache.
The status code is optional. Do not infer that an endpoint enforces conditional writes merely because HTTP defines the code. Read the endpoint contract and check what happens when a write omits the condition. An API that accepts unconditional updates needs a deliberate policy for clients that do not participate in optimistic concurrency.
The same question extends beyond the public HTTP handler. If a background importer or administrative path can update the underlying state, the representation validator and persistence logic must account for those changes where relevant. That is an application-design requirement to investigate, not a guarantee supplied by the presence of a response header.
Documentation: Additional HTTP Status Codes, RFC 6585, HTTP Semantics, RFC 9110.
The comparison and write need one concurrency boundary
A handler that reads a version, compares it in application code and later performs an unrelated unconditional database write can recreate the race inside the server. Another writer may change the state between the comparison and the mutation. The HTTP-facing condition must be implemented using a persistence mechanism that preserves the intended stale-write rejection.
An engineering option is a conditional database update tied to the stored revision, or an appropriate transaction or locking design. The right mechanism depends on the data model and database. RFC 9110 specifies the observable HTTP behavior; it does not prescribe a SQL statement or certify a framework's transaction setup.
Also keep the scope honest. A validator for one document does not by itself protect an invariant spanning several resources, reserve inventory elsewhere or make an external notification part of the same commit. Those boundaries need their own design and acceptance checks.
Documentation: HTTP Semantics, RFC 9110, Azure Blob Storage concurrency.
A provider example is useful within its operation contract
Microsoft documents an optimistic-concurrency flow for Azure Blob Storage: retrieve a blob and its ETag, supply that original value in the write's If-Match condition, and handle a changed tag with a 412 response. Its example deliberately introduces another update between the read and the attempted conditional write. This is Microsoft's documented example, not a cloud test performed for this article.
The provider's REST reference also distinguishes operations and service versions. Its rules for combining conditional headers and accepting multiple tag values differ between some reads and writes. A feature described for a read operation must not silently become a claim about every write operation.
The general lesson is to record the precise endpoint, method, resource scope, API version and SDK behavior. Standards explain the protocol mechanism. Provider documentation explains how a particular operation exposes it. Neither makes an untested application implementation correct by association.
Documentation: Azure Blob Storage concurrency, Azure Blob conditional headers.
Rejection, retry and authorization are separate decisions
After a stale-write rejection, a client usually needs a new view of the resource before choosing a revised mutation. Preserve the pending edit and resolve the conflict deliberately. A bounded retry can be appropriate for a recomputed operation, but repeatedly resending the old representation with newly fetched tags can repeatedly discard other people's work.
A lost response presents another uncertainty: the client might not know whether its previous write succeeded. Inspect the API's documented recovery behavior and current resource state before issuing a replacement action. If-Match is not a general exactly-once business-operation guarantee or a substitute for a provider's idempotency contract.
Nor is an entity tag an authorization credential. RFC 9110 places normal request checks before precondition evaluation, with applicable redirects and earlier failures taking precedence. Having a matching tag does not grant permission to modify a resource, and a response other than 412 does not by itself prove that the version condition was ignored.
Documentation: HTTP Semantics, RFC 9110, MDN conditional requests guide.
What a useful acceptance test would establish
In an isolated application test, start two clients from the same actual representation and validator. Let the first conditional update finish, then attempt the second update with the stale validator. Inspect both the response and the resulting resource, including the field changed by the first client. A status-code assertion alone can miss a handler that returned an error after already changing data.
Then cover the endpoint's documented cases: a missing condition, a weak validator, an existence wildcard, resource deletion between read and write, and the API's lost-response recovery path. Include concurrent writers through the real persistence boundary rather than testing only a mocked string comparison. These are proposed checks, not tests executed here.
A good result states which operation and version were tested, which state changes were rejected and what remained outside scope. The practical goal is a conditional update whose boundaries are understood, not a blanket claim that ETags make all writes safe.
Documentation: HTTP Semantics, RFC 9110, Additional HTTP Status Codes, RFC 6585, Azure Blob Storage concurrency.
Related reading
Stale-state protection and duplicate-action prevention address different failure modes. See why idempotency-key lifetimes matter when retrying an action. That guide covers operation identity and uncertain outcomes rather than representation conflicts.
Sources and scope
Documentation checked November 23, 2026. The protocol details come from the RFCs; MDN supplies explanatory context and Microsoft supplies a provider-specific example. No server, framework, proxy, production workload or cloud account was tested. The fictional sequence and suggested acceptance checks are not measured results.
Comments
Post a Comment