InterviewBuddy
All interview questions

How do ETags help prevent lost updates in an API?

Advanced

Answer

Return a resource version as an ETag and require If-Match on updates. Atomically reject writes whose version no longer matches.

Explanation

The version check and write must be coordinated to prevent races.

Example

Client submits If-Match for version 7; server at version 8 returns 412.