Preventing Lost Updates

Optimistic Concurrency

Imagine two administrators read the same user record. Administrator A updates it. Administrator B then submits an update based on stale data and accidentally overwrites A's changes.

ETags and If-Match can prevent this.

The client sends the representation version it read. If the server's current version differs, the server returns 412 Precondition Failed rather than silently overwriting newer data.

This technique is essential for collaborative systems and APIs where concurrent edits are possible.

Key Takeaways
  • ETags support efficient caching.
  • Conditional requests can prevent stale writes.
  • HTTP provides mechanisms for optimistic concurrency.