Agent Wranglers

API-33Recommended

Stop lost updates with ETags

Send an ETag with every resource, and require If-Match on updates, so one client can't silently overwrite another's change.

How to do it

Use strong ETags, such as a version number in quotes, because If-Match never matches a weak W/ tag. Answer 412 when the If-Match value no longer matches, as RFC 9110 defines. Answer 428 when an update arrives without If-Match on a resource that requires it, as RFC 6585 defines. The same ETags let readers use conditional requests. The database side is in conditional writes.

How to check

Two clients read the same order, and both send a PATCH with the first ETag. The second gets 412. A PATCH without If-Match gets 428.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/reliability/optimistic-concurrency">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.