
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYou've correctly identified the classic race condition problem with drafts overwriting backend updates. The good news is Sanity provides a robust solution through optimistic concurrency control using the ifRevisionID parameter.
ifRevisionID for Backend MutationsWhen your backend updates documents, you should use the ifRevisionID parameter in your patch mutations. This prevents the exact scenario you're describing:
// In your backend code
await client
.patch(documentId)
.ifRevisionID(currentRevisionId) // Only apply if this revision matches
.set({ yourField: newValue })
.commit()If the revision ID doesn't match (because a draft exists or someone else modified it), the mutation will fail with a 409 Conflict status, allowing you to:
The issue stems from Sanity's draft system:
drafts.) is createddrafts. prefix)For your backend:
ifRevisionID in mutations to detect conflictsdrafts.{documentId} and handle accordinglyFor your editors (workflow improvements):
_updatedAt on the published doc is newer than when the draft was createdAlternative architecture: If your backend updates are frequent and critical, consider whether editors should be modifying those fields at all. You might:
// Backend mutation with conflict handling
try {
const doc = await client.getDocument(docId)
await client
.patch(docId)
.ifRevisionID(doc._rev)
.set({ backendField: value })
.commit()
} catch (error) {
if (error.statusCode === 409) {
// Conflict detected - draft exists or doc changed
console.log('Conflict: document was modified')
// Handle: retry, merge, or alert
}
}The ifRevisionID approach is exactly what the Transactions documentation recommends for preventing lost updates in read-write cycles. It's Sanity's built-in solution for optimistic locking and will catch both draft conflicts and concurrent modifications.
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store