{"success":true,"name":"handle-concurrent-api-updates-with-versions-not-last-write-w","description":"Two clients can update the same resource through the API at once","category":"ai-brimind","path":"ai-brimind/handle-concurrent-api-updates-with-versions-not-last-write-w/SKILL.md","file":"SKILL.md","content":"---\nname: handle-concurrent-api-updates-with-versions-not-last-write-w\ndescription: \"Two clients can update the same resource through the API at once\"\n---\n\n# Handle Concurrent API Updates With Versions, Not Last-Write-Wins\n\n## When to use\nAn endpoint updates a shared resource that multiple users or tabs can edit, and nothing detects that one update would silently overwrite another.\n\n## Example request\nTwo admins edit the same record → the second save erases the first's changes without warning; optimistic locking with a version field is the standard guard. — Client sends the full object back on save → fields it never touched get overwritten to stale values; PATCH with only changed fields shrinks the blast. — Update succeeds but was based on data read minutes ago → decisions made on stale state; ETag/If-Match is the HTTP-native version check. — Conflict detected but the API just errors → user loses their edits; a 409 with the current state lets the client merge or retry sanely.\n\n## Instructions\nAct as a concurrency-aware API designer who assumes every shared resource is being edited by two people right now. For update endpoints: 1) Ask the collision question: if two clients read the same resource and both save, is silently losing one edit acceptable? If not, last-write-wins is a bug, not a default. 2) Use the standard mechanisms before inventing: a version/updatedAt column checked on write (optimistic locking), or HTTP ETag with If-Match — check what the framework/ORM already supports. 3) On version mismatch return 409 with enough current state that the client can show a sensible conflict experience — detection without a recovery path just converts silent loss into loud loss. 4) Prefer PATCH semantics for partial edits so untouched fields can't be stomped by stale full-object PUTs. 5) If you're unsure whether concurrent edits actually happen, check the resource's usage — multi-user, multi-tab, or retry-prone paths mean yes. Only ship once the conflict path is confirmed by simulating two racing updates, and explain how the version check converts silent data loss into a handled case rather than hoping edits never collide.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #907\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}