Concurrency and last-writer-wins semantics
Audience: customers building integrations that mutate the same content from multiple writers (e.g., a sync pipeline + the admin UI editing the same article, or two import jobs racing on the same slug). Most customers don't need to think about this.
Parallel writes to the same slug — for example a POST /api/import/json and a DELETE /api/content/:type/:slug firing at nearly the same moment — are non-deterministic: the DELETE can "win" or "lose" depending on which mutation lands at the engine writer last.
This page documents the actual semantics, why they're what they are, and what to do if you need stronger guarantees.
What you get today
Each single mutation is atomic. The engine writer is single-instance + sequenced; one create/update/delete lands as one writer transaction. There's no half-state.
Across mutations on the same slug, last-writer-wins. If you fire:
T+0ms POST /api/import/json (with the slug "x" in the batch)
T+5ms DELETE /api/content/article/x
The order they arrive at the writer determines the final state. If DELETE lands first, then the import recreates the slug. If the import lands first, DELETE removes it. There's no version negotiation between the two.
This is intentional — the engine is single-writer, sequenced, and append-only. It's a coherent contract; it's just not a locking contract.
When this matters
| Scenario | Risk |
|---|---|
| One admin user editing one article | None — single source. |
| Sync pipeline + admin both touching the same slug | DELETE in admin can be silently undone by next sync tick. |
| Two import jobs racing on overlapping slugs | One job's writes overwrite the other's; no error surfaced. |
| MCP agent editing while a build is publishing | Build reads a frozen snapshot — safe. |
What to do if you need stronger guarantees
1. Idempotent imports
If your sync pipeline is the source of truth, design imports so the current state of the source is what lands — and DELETE in the admin will get clobbered on next sync. This is the cleanest model.
2. Optimistic concurrency (opt-in)
PATCH /api/content/:type/:id accepts a version precondition. Send the version you last read as an If-Match header (or a body expectedUpdatedAt); the write applies only if the item is still at that version. If it moved since you read it, you get a 409 carrying code: "stale_write", the currentUpdatedAt, and the current record — reload, reapply your change, and retry.
# read — the response carries the version as an ETag
GET /api/content/article/my-post -> ETag: "2026-11-03T12:00:00.000Z"
# write only if it hasn't changed since you read it
PATCH /api/content/article/my-post
If-Match: "2026-11-03T12:00:00.000Z"
{ "fields": { "title": "New title" } }
-> 200 + ETag: "<new version>" (applied)
-> 409 { "code": "stale_write", "currentUpdatedAt", "current" } (someone else moved it)
The precondition is opt-in: omit If-Match/expectedUpdatedAt and you get the last-writer-wins default described above, so existing integrations are unaffected.
Bulk upserts take the same precondition per item. On POST /api/content/:type/_upsert, give any item an expectedUpdatedAt; if that item has moved, it comes back as action: "conflict" (with its currentUpdatedAt) and is counted in a conflicts total — the rest of the batch still applies. A conflict is reported separately from a hard failed, and a brand-new key is still created (the precondition guards updates, not creates).
DELETE takes the same precondition. Send If-Match: "<updatedAt>" (or a body expectedUpdatedAt) on DELETE /api/content/:type/:id; the item is removed only if it's still at that version, otherwise you get the same 409 { code: "stale_write", currentUpdatedAt, current } — so a delete can't silently remove an item someone just edited. Omit it for the legacy unconditional delete.
DELETE /api/content/article/my-post
If-Match: "2026-11-03T12:00:00.000Z"
-> 204 (deleted)
-> 409 { "code": "stale_write", "currentUpdatedAt", "current" } (someone else moved it — reload first)
3. Don't race in the first place
If you have one workflow that DELETEs and another that imports, gate the import on "is the content currently deleted?" via a GET before the POST. Race window shrinks dramatically and is acceptable for most pipelines.
4. Use bulk endpoints with skipExisting: true
POST /api/import/json {records: [...], skipExisting: true} won't overwrite existing slugs — its writes use MERGE ... ON CREATE SET so a row already present is a no-op. Combined with explicit DELETE only via the admin, this prevents most race outcomes.
Why we don't lock
Locking on every slug would:
- Push contention into the engine writer (already the system bottleneck).
- Make import-throughput dependent on lock-acquisition cost.
- Surface a class of deadlock and lock-timeout errors the system is currently free of.
Sequenced last-writer-wins is the right default for an append-only content store. Stronger guarantees layer on top: the opt-in If-Match precondition (section 2) is one such layer, available now on PATCH, DELETE, and bulk _upsert. Others (opaque session tokens, leases) remain things we'll add when customer demand justifies the engineering cost.
Audit trail still works
Even when last-writer-wins, the bitemporal audit chain records every mutation. You can ask "what did article X look like at 14:23:01" and the answer is exact, even if 14:23:02 then deleted it and 14:23:03 recreated it. The history is whole; the current state is whatever the last writer said.
Related
- HTTP API — the endpoint surface
- Audit chain verification — the tamper-evident history that stays whole even under last-writer-wins