---
title: "Snapshots"
url: "https://nsta1.github.io/Orleans.Lattice/samples/Snapshots/README.html"
source: "https://github.com/NSTA1/Orleans.Lattice/blob/release/9.9/samples/Snapshots/README.md"
documents: "Orleans.Lattice 9.9.0 (release line 9.9)"
built: "2026-10-04"
all-pages: "https://nsta1.github.io/Orleans.Lattice/llms.txt"
---
# Snapshots

Part of [Samples](../index.md).

## What it shows

`SnapshotAsync` **copies a tree** into a new destination tree - an offline
snapshot as a point-in-time copy - which is useful for backups, read-only
analytics forks, or cloning a dataset for experimentation. The copy carries only
live entries (never tombstoned or expired ones) and follows the tree's shard
map, so it covers every physical shard the map routes to, including one an
adaptive split added; an online snapshot does not mirror typed CRDT deltas or
bulk appends (see
[Snapshots](../../docs/lattice/snapshots.md)). This
sample uses `SnapshotMode.Offline`: every source
shard is locked when the copy starts and each is unlocked again once its own
entries have been copied, producing a strictly consistent image.
It then verifies the copy matches the source and shows the two trees are fully
independent (editing one never affects the other).

Switching to `SnapshotMode.Online` is a one-line change (`SnapshotMode.Online`):
the source then stays readable **and writable** throughout the copy, with live
mutations mirrored to the destination. Offline trades source availability (a
shard stays locked until its own copy completes) for the simplest consistency
story; online keeps the source hot.

> **Runtime note:** `SnapshotAsync` runs a crash-safe coordinator that advances
> one shard step per two-second timer tick, and an offline copy spends two ticks
> on each shard (copy it, then unlock it). A tree defaults to 64 physical shards,
> so this sample takes a few minutes to complete even though it only holds 12
> keys - snapshot cost scales with **shard count, not key count**.

## Run it

```
dotnet run --project samples/Snapshots
```

## Expected output

The progress dots appear once per second while the copy runs; the total time
depends on your machine (about 4-5 minutes for the default 64-shard tree).

```
Silo starting... ready.

Seeding source tree 'orders' with 12 keys...
  source count = 12

Offline snapshot: orders -> orders-backup ....[ ~4 minutes of progress dots ].... done in 259s.

Verifying the snapshot:
  backup live-key count = 12 (expected 12)
  backup[order:005]     = "amount=50"
  source readable again = True

Independence after editing each tree separately:
  backup[order:005] = "edited-in-backup" (edited)
  source[order:005] = "amount=50" (unchanged)
  source[order:999] = "new-in-source" (new)
  backup[order:999] = <absent> (not in the snapshot)

Done: the offline snapshot produced an independent point-in-time copy.
```

## When to use

- Backups or scheduled point-in-time copies of a tree.
- Forking a dataset into an independent tree for analytics or experimentation
  without touching production data.
- Online mode when the source cannot tolerate any read/write interruption
  during the copy.

## When not to use

- Isolating a **single reader** from concurrent writes - you do not need a whole
  second tree; open a snapshot cursor instead (see
  [SnapshotCursors](../SnapshotCursors/README.md)).
- Latency-sensitive paths that need the copy to finish quickly on a
  high-shard-count tree - snapshot time scales with shard count.

## Feature doc

- [Snapshots](../../docs/lattice/snapshots.md)
