---
title: "Atomicity Guarantees - Atomic Multi-Key Writes"
url: "https://nsta1.github.io/Orleans.Lattice/docs/lattice/atomic-writes/atomicity-guarantees.html"
source: "https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/docs/lattice/atomic-writes.md?plain=1#L27-L111"
agent_spec: "https://nsta1.github.io/Orleans.Lattice/docs/agents/invariants.yaml"
package: "Orleans.Lattice"
version: "10.5.0"
documents: "Orleans.Lattice 10.5.0 (release line 10.5)"
built: "2026-12-05"
all-pages: "https://nsta1.github.io/Orleans.Lattice/llms.txt"
bundle: "https://nsta1.github.io/Orleans.Lattice/docs/lattice/llms-full.txt"
---
# Atomicity Guarantees

Part of [Atomic Multi-Key Writes](../atomic-writes.md).

This section describes the **atomicity** contract of the saga. For the
reader-visibility model - the per-tree transaction registry's linearization
point and how each read path consults it - see
[Consistency: Atomic visibility](../consistency.md#atomic-visibility).
The atomicity guarantee is **universal**: it holds within a single
tree on the local cluster *and* across every cluster the tree
replicates to. Receiver-side replication routes prepared writes and
the per-shard terminal mark through the same transaction-registry
linearization point used locally, so a remote reader concurrent with
replication of a `SetManyAtomicAsync` observes either zero or all of
the saga's keys - never a partial view (see Consistency for details).

Given a batch `[(k0, v0), (k1, v1), ..., (kN-1, vN-1)]`, a successful
`SetManyAtomicAsync` call guarantees:

1. **All-or-nothing commit.** On successful return every `ki` holds `vi` as
   its last-writer-wins (LWW) value, or - if the saga failed - every `ki`
   holds the value it had before the saga started (its pre-saga value; a
   key that did not exist before the saga stays absent).
2. **Sequential per-key ordering.** Each key is written at most once by the
   saga, with a monotonically-increasing [Hybrid Logical Clock](../state-primitives.md)
   timestamp. An abort issues no rollback writes - the saga's prepared writes
   were never visible - so a write an external writer raced in during the
   saga is never overwritten by a rollback.
3. **Crash recovery.** If the silo hosting the saga grain crashes mid-flight,
   a keepalive reminder resumes the saga on reactivation and drives it to a
   terminal state (either Completed or Compensated + Completed). A saga that
   had already recorded its commit is completed; one that had not is
   compensated, because by then its caller has been answered (see
   [Batches whose caller was answered](../atomic-writes.md#batches-whose-caller-was-answered)).
4. **Input validation.** Duplicate keys and null keys fail fast with
   `ArgumentException` before any write is attempted. A null value fails fast
   for an upsert entry, but is permitted for a delete entry in a mixed
   set+delete batch (a delete carries no value). An empty batch returns
   immediately without contacting any leaf grain. The tree's write bounds are
   applied up front as well, before the saga starts, so a batch they refuse
   stages and persists nothing: with
   [`MaxKeyLength`](../configuration/options-reference-2.md#maxkeylength) or
   [`MaxValueSizeBytes`](../configuration/options-reference-2.md#maxvaluesizebytes) set, an upsert
   with a longer key or a larger value fails with `ArgumentException`, and
   while the tree is at an enforcing
   [`MaxLiveKeys`](../configuration/options-reference-2.md#maxlivekeys) or
   [`MaxEstimatedBytes`](../configuration/options-reference-2.md#maxestimatedbytes) cap (a
   best-effort check against a cached footprint) the call fails with
   `LatticeQuotaExceededException`. A delete-only batch skips the caps,
   because it can only shrink the tree. Delete keys are not length-checked up
   front: a delete key longer than `MaxKeyLength` is refused only when the
   saga writes the batch, so the saga aborts and the call throws
   `InvalidOperationException`. A registered `ILatticeWriteInterceptor`
   (schema enforcement and schema versioning) also runs over the upserts up
   front: a transformed value is the one staged, and a value it rejects or
   dead-letters fails the whole call with `LatticeWriteRejectedException`
   before the saga starts. Deletes are not intercepted.
5. **Idempotent client retry.** A re-invocation of the same saga grain (same
   `treeId` + `operationId`) after successful completion returns success
   without re-executing. A re-invocation after a compensated-failure replays
   the original `InvalidOperationException` with the preserved failure
   message. A re-invocation passes the same up-front checks as a first call,
   though, so they can refuse it before it reaches the saga - while the tree
   is at an enforcing cap, for example, the retry throws
   `LatticeQuotaExceededException` instead of returning the original outcome.

## What `SetManyAtomicAsync` does **not** guarantee

- **Cross-tree atomicity (this call).** A `SetManyAtomicAsync` call is
  bound to a single tree (`ILattice`) and the per-tree transaction
  registry is its unit of atomic visibility. To commit a batch
  spanning two or more distinct trees all-or-nothing, use
  `IGrainFactory.SetManyAtomicAsync` (or the
  `BeginAtomicWrite` fluent builder) - a two-level saga that layers a
  single global decision over each tree's per-tree saga. See
  [Cross-tree (multi-tree) atomic writes](cross-tree-multi-tree-atomic-writes.md)
  below.
- **Ordering across distinct sagas.** Two concurrent `SetManyAtomicAsync`
  calls touching overlapping keys are resolved pairwise by LWW - the later
  HLC tick wins per key. There is no global transaction order.
- **Abort durability in every failure mode.** If recording the abort
  decision or broadcasting the abort terminals fails, the saga stays in its
  compensate phase and the keepalive reminder keeps re-driving it until it
  completes; operators can inspect the failure message the saga records in
  its persisted state. This is rare in practice and limited to
  total-storage-outage scenarios.

Next: [How It Works](how-it-works.md). Contents: [Atomic Multi-Key Writes](../atomic-writes.md).
