Learn VisualLearn API

The Server Applies the Write Only If the If-Match ETag Matches

When a client reads a resource, it receives the ETag for that moment. When it writes, it sends that ETag in an If-Match header, asking for the write only if the resource is still as it was when read.

If nothing has changed since the read, the resource's current ETag still matches. In that case, the server applies the write as usual.

If another write happened in between, the current ETag no longer matches. In that case, the server doesn't apply the write and rejects it with 412 Precondition Failed.

This lets the server stop the second writer from silently overwriting the first writer's change. Each writer believes they are writing to the version they read, so neither would notice the conflict on their own.

GOAL

Explain how If-Match with an ETag prevents a lost update, and what 412 Precondition Failed signals.

Two clients read the same resource with ETag "v1". Client A writes first, and the resource's ETag becomes "v2". Client B then sends its write with If-Match: "v1". What happens?