How can ETags be used for "Optimistic Concurrency Control"?
Last updated
A
GETreturns anETag(a version fingerprint). The client then sends it asIf-Matchon itsPUT/PATCH/DELETE.If the ETag still matches, the server applies the change and returns a new ETag. Otherwise it returns
412 Precondition Failed, and the client re-reads and retries, which prevents lost updates.It is optimistic because no locks are held and conflicts are caught only at write time. This scales well over stateless HTTP when collisions are rare.