---
title: "TTL and soft delete"
url: "https://nsta1.github.io/Orleans.Lattice/docs/videos/ttl-and-soft-delete.html"
source: "https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/docs/videos/ttl-and-soft-delete.md"
agent_spec: "https://nsta1.github.io/Orleans.Lattice/docs/agents/concepts.yaml"
documents: "Orleans.Lattice 10.5.0 (release line 10.5)"
built: "2026-12-05"
all-pages: "https://nsta1.github.io/Orleans.Lattice/llms.txt"
---
# TTL and soft delete

Part of [Videos](index.md).

Entries can expire on their own, and a deleted tree can be recovered inside its retention window.

Video: [TTL and soft delete, video, 1:50](../../media/ttl-and-soft-delete-391a0143a271.mp4). Captions: [English](../../media/ttl-and-soft-delete-391a0143a271.vtt).

1:50, English captions, [Download the MP4](../../media/ttl-and-soft-delete-391a0143a271.mp4) (5.9 MB)

## Transcript

### TTL and soft delete

Atomic writes showed how related changes become visible as a whole. Here, we ask how data goes away: on its own, or by mistake.

This is TTL and soft delete: entries can expire on their own, and a deleted tree can be recovered inside its retention window.

### Entries that expire

A session should not live for ever. Write it with a time to live, here thirty minutes.

The silo turns that duration into an absolute expiry time, so a client with a skewed clock does not move it.

Once that time passes, the entry is gone from every read. A get returns nothing, an existence check says false, and scans and counts skip it.

### Refresh and reaping

Expiry follows the write that wins. A later write replaces the entry as usual, and a winning plain write without a time to live clears the expiry.

On a CRDT entry, expiries merge by taking the later one, so a refresh only ever extends it.

An expired entry is not deleted straight away. Compaction reaps it after the tombstone grace period, so a lagging peer cannot bring it back.

### Soft delete

Deleting a whole tree is a soft delete. The tree becomes inaccessible at once: its reads and writes throw.

But its data is not gone. It is kept for a retention window, seventy-two hours by default, before it is purged.

### Recovery

Inside that window, recovering the tree makes it accessible again, with all the data it held before the delete.

Once the purge has started, it is too late; and once the purge is complete, the data is gone.

### Where next

Next on Build: Going durable. The links are on this episode's page in the documentation.

## The code on screen

The episode writes a session with a thirty-minute time to live, then deletes a tree and recovers it inside its retention window. The snippets are compiled with the rest of the documentation.

```csharp verify
var session = new User("alice", 1);

await lattice.SetAsync("session:42", session, TimeSpan.FromMinutes(30));
```

```csharp verify
var tree = grainFactory.GetGrain<ILattice>("my-tree");
await tree.DeleteTreeAsync();
```

```csharp verify
var tree = grainFactory.GetGrain<ILattice>("my-tree");
await tree.RecoverTreeAsync();

// Tree is accessible again - all data from before the delete is restored.
byte[]? value = await tree.GetAsync("customer-123");
```

## Where next

- **Next on Build:** [Going durable](going-durable.md)
- **The pages it introduces:** [TTL](../lattice/ttl.md)
