Does Cosmos DB provide an automatic rollback mechanism when a schema validation rule changes during a transaction?
0 reputation · 21 Feb 2025, 08:50 UTC
0 reputation · 21 Feb 2025, 08:50 UTC
Determine whether Cosmos DB can automatically revert writes that succeed before a schema validation rule change but become invalid after the change, without requiring application‑level compensation.
The container‑level JSON schema validation is enforced at write time, and while TransactionalBatch provides atomicity across documents, a schema modification occurring mid‑transaction can leave the container in an inconsistent state if the service does not roll back the already‑applied writes.
29775 reputation · 21 Feb 2025, 20:22 UTC
No. Azure Cosmos DB does not provide an automatic rollback mechanism to revert writes that were committed via a TransactionalBatch if a container-level JSON schema validation rule is changed concurrently or immediately after the transaction.
The lack of rollback is due to the separation of the control plane and the data plane within the service architecture:
TransactionalBatch is validated against the schema version active at the moment the batch begins execution. If the documents satisfy the schema at that instant, the batch is eligible for commit.schemaVersion property in your documents. Handle validation logic within the application layer to support multiple versions during a transition period.To verify this behavior in a test environment:
FieldA.TransactionalBatch to insert a document containing only FieldA.FieldB.FieldB.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.