API · v1 · stable
CODEMETA OSDeveloper Center
EN
Open console
Concept

Optimistic locking

Reading time · 5 minUpdated · 1 May 2026

Every entity in Codemeta OS has a numeric version field. It starts at 1 and is incremented by one on every successful update. You use it to detect concurrent writes.

How it works

  1. You read an entity via GET and note its version.
  2. You send a PATCH and put the noted version in the body object.
  3. If the database version still matches, the update goes through and version is set to <n+1>.
  4. If not, the API responds with 409 Conflict and you know that another writer got there before you.

Example

# Step 1: read the current state
curl https://os.codemeta.de/api/v1/tickets/<id> \
  -H "X-Tenant-Id: $TENANT" \
  -b cookies.txt
# → { "id":"…", "version": 7, "title":"…", … }

# Step 2: update with version
curl -X PATCH https://os.codemeta.de/api/v1/tickets/<id> \
  -H "X-Tenant-Id: $TENANT" \
  -H "Content-Type: application/json" \
  -b cookies.txt \
  -d '{"version": 7, "priority": "high"}'

If the server version is now 8, you get:

{
  "type": "https://codemeta-os.de/probs/version-conflict",
  "title": "Version conflict",
  "status": 409,
  "detail": "The entity has been modified since you last read it.",
  "currentVersion": 8
}

Strategy for 409

  • Read again. Fetch the current entity, merge your change with the new fields, and send the update with the new version.
  • Don’t blindly retry. Without re-reading, your retry runs into the same 409 response.
  • In UI workflows, ask the user. If the other changes collide in substance, an auto-merge strategy is rarely right.

Search