Atomic writes
This page is part of the documentation for Orleans.Lattice 10.5.0 (release line 10.5), built 2026-12-05. It is also published as markdown, with every table and list, at atomic-writes.md, and llms.txt lists every page.An atomic write makes related key changes visible together, or not at all.
Transcript
Atomic writes
Scans, filters and cursors showed how to choose what to read. Here, we ask what happens when one change touches several keys.
This is Atomic writes: related changes become visible as a whole, or not at all.
The partial-write problem
Suppose an order changes two keys: its status and its tracking reference. They belong together; once one is live, the other must be too.
Two ordinary writes are two chances to stop. If the second fails, the first may already be visible.
A non-atomic batch remains useful when throughput matters and partial application is acceptable. It does not make those writes all-or-nothing.
One batch, one decision
For a batch in one tree, use the atomic write surface.
On success, the whole batch commits. If the saga aborts, none of its writes become visible. A caller-side timeout leaves the outcome unknown.
Readers do not see half of this batch. Its prepared writes stay hidden until one commit decision makes them visible together.
An abort drops those hidden writes; it does not need to write the old values back.
Across trees
Sometimes one change spans distinct trees: an order leaves one tree and appears in another.
The single-tree call cannot cover both. The cross-tree builder stages each tree's part under one stable operation identifier.
One shared decision applies to every participating tree: commit them all, or commit none.
The boundary
That is atomicity for the write, not a snapshot read across trees.
Two separate reads at different moments can straddle the decision: one may return the old state, and the next the new state. For a consistent view of one tree, use a snapshot entry cursor; every page reflects the tree state captured at open.
Where next
Next on Build: TTL and soft delete. The deep dive on how this works is Atomic commit without consensus. The links are on this episode's page in the documentation.
The code on screen
The cross-tree example moves an order from one tree to another in one atomic write. The snippet is compiled with the rest of the documentation.
// Move a row between trees in one cross-tree saga.
await grainFactory
.BeginAtomicWrite("rekey:order-42")
.ForTree("orders-east")
.Delete("order:42")
.ForTree("orders-west")
.Set("order:42", new Order("42", 250m))
.CommitAsync(cancellationToken);
Where next
- Next on Build: TTL and soft delete
- The deep dive: Atomic commit without consensus
- The pages it introduces: Atomic writes